aboutsummaryrefslogtreecommitdiffstats
path: root/noice.c
diff options
context:
space:
mode:
authorsin <sin@2f30.org>2016-01-06 15:53:04 +0000
committersin <sin@2f30.org>2016-01-06 15:53:04 +0000
commitfa6b45a96de53621d4e89bd63ee810210712f043 (patch)
tree60775d70d62c4ed7123cc90922a83ae517511fa1 /noice.c
parente27af6f1dbc804e90a3b98f19afdf1055bab8dc9 (diff)
downloadnoice-fa6b45a96de53621d4e89bd63ee810210712f043.tar.gz
Avoid unneeded memory allocation in xdirname()
Diffstat (limited to 'noice.c')
-rw-r--r--noice.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/noice.c b/noice.c
index ada28fc..5067424 100644
--- a/noice.c
+++ b/noice.c
@@ -158,21 +158,17 @@ xstrdup(const char *s)
char *
xdirname(const char *path)
{
- char *p, *tmp;
+ char tmp[PATH_MAX], *p;
/* Some implementations of dirname(3) may modify `path' and some
* return a pointer inside `path' and we cannot free(3) the
* original string if we lose track of it. */
- tmp = xstrdup(path);
+ strlcpy(tmp, path, sizeof(tmp));
p = dirname(tmp);
- if (p == NULL) {
- free(tmp);
+ if (p == NULL)
printerr(1, "dirname");
- }
/* Make sure this is a malloc(3)-ed string */
- p = xstrdup(p);
- free(tmp);
- return p;
+ return xstrdup(p);
}
void
Un proyecto texto-plano.xyz