commit 8ded4053dbc591e4027f0e57b132fdead3ed35b5
parent 817b53cfcef7d802db253132cb8bcee3accb56bb
Author: sin <sin@2f30.org>
Date: Fri, 23 Aug 2013 14:49:54 +0100
Don't strdup() for basename()
Diffstat:
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/smdev.c b/smdev.c
@@ -167,7 +167,7 @@ parsepath(struct rule *rule, char *devpath, size_t devpathsz,
char *devname, size_t devnamesz)
{
char buf[BUFSIZ], *p;
- char *dirc, *basec;
+ char *dirc;
if (rule->path[0] != '=' && rule->path[0] != '>')
eprintf("Invalid path '%s'\n", rule->path);
@@ -184,13 +184,10 @@ parsepath(struct rule *rule, char *devpath, size_t devpathsz,
if (!(dirc = strdup(&rule->path[1])))
eprintf("strdup:");
snprintf(buf, sizeof(buf), "/dev/%s", dirname(dirc));
- if (!(basec = strdup(&rule->path[1])))
- eprintf("strdup:");
- strlcpy(devname, basename(basec), devnamesz);
+ strlcpy(devname, basename(&rule->path[1]), devnamesz);
snprintf(devpath, devpathsz, "%s/%s",
buf, devname);
free(dirc);
- free(basec);
} else {
strlcpy(devname, &rule->path[1], devnamesz);
snprintf(devpath, devpathsz, "/dev/%s", devname);