From: Rich Felker Date: Sat, 18 Jun 2011 11:41:14 +0000 (-0400) Subject: fix memory leak on failure in realpath X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=commitdiff_plain;h=d43ff110bcb258df61448d21da3b1a89088388f6 fix memory leak on failure in realpath --- 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;