diff options
author | Mattias Andrée <maandree@operamail.com> | 2015-11-19 22:33:16 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2015-11-19 22:33:16 +0100 |
commit | 2a1a7a6a1aa8e4f79fc9424b16dd9a3902d2eb4d (patch) | |
tree | 8c6f40c4589469b77e7a083a3865b29ae2c92b7b /src/unistd | |
parent | fix issue #2 (diff) | |
download | slibc-2a1a7a6a1aa8e4f79fc9424b16dd9a3902d2eb4d.tar.gz slibc-2a1a7a6a1aa8e4f79fc9424b16dd9a3902d2eb4d.tar.bz2 slibc-2a1a7a6a1aa8e4f79fc9424b16dd9a3902d2eb4d.tar.xz |
fix memory leak at failure of execveat (issue #3)
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/unistd')
-rw-r--r-- | src/unistd/execat.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/unistd/execat.c b/src/unistd/execat.c index bcff176..a7de5dd 100644 --- a/src/unistd/execat.c +++ b/src/unistd/execat.c @@ -380,7 +380,8 @@ int execveat(int dirfd, const char* path, char* const argv[], char* const envp[] { /* TODO use linux system call if available */ struct stat attr; - char* pathname; + char* pathname = NULL; + int saved_errno; if (*path == '/') return execve(path, argv, envp); @@ -401,7 +402,12 @@ int execveat(int dirfd, const char* path, char* const argv[], char* const envp[] return -1; sprintf(pathname, "/dev/fd/%i%s%s", dirfd, *path ? "/" : "", path); - return execve(pathname, argv, envp); + execve(pathname, argv, envp); + + saved_errno = errno; + free(pathname); + errno = saved_errno; + return -1; } |