mirror of
git://git.musl-libc.org/musl
synced 2025-03-06 20:48:29 +01:00
fix memory leak on failure in realpath
This commit is contained in:
parent
5a2e74ebd2
commit
d43ff110bc
1 changed files with 4 additions and 4 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue