summaryrefslogtreecommitdiff
path: root/src/misc
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-06-18 07:41:14 -0400
committerRich Felker <dalias@aerifal.cx>2011-06-18 07:41:14 -0400
commitd43ff110bcb258df61448d21da3b1a89088388f6 (patch)
tree31e2e8af32a275f9faef881c9e5cf1f33c25b6d2 /src/misc
parent5a2e74ebd2dc6d2fb3766662e68dcbc62e3e9081 (diff)
downloadmusl-d43ff110bcb258df61448d21da3b1a89088388f6.tar.gz
musl-d43ff110bcb258df61448d21da3b1a89088388f6.tar.bz2
musl-d43ff110bcb258df61448d21da3b1a89088388f6.tar.xz
musl-d43ff110bcb258df61448d21da3b1a89088388f6.zip
fix memory leak on failure in realpath
Diffstat (limited to 'src/misc')
-rw-r--r--src/misc/realpath.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/misc/realpath.c b/src/misc/realpath.c
index 8dcf5ec9..ef156fcf 100644
--- a/src/misc/realpath.c
+++ b/src/misc/realpath.c
@@ -19,16 +19,16 @@ char *realpath(const char *filename, char *resolved)
return 0;
}
+ fd = open(filename, O_RDONLY|O_NONBLOCK);
+ if (fd < 0) return 0;
+ snprintf(buf, sizeof buf, "/proc/self/fd/%d", fd);
+
if (!resolved) {
alloc = 1;
resolved = malloc(PATH_MAX);
if (!resolved) return 0;
}
- fd = open(filename, O_RDONLY|O_NONBLOCK);
- if (fd < 0) return 0;
- snprintf(buf, sizeof buf, "/proc/self/fd/%d", fd);
-
r = readlink(buf, resolved, PATH_MAX-1);
if (r < 0) goto err;
resolved[r] = 0;