aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-11-19 22:33:16 +0100
committerMattias Andrée <maandree@operamail.com>2015-11-19 22:33:16 +0100
commit2a1a7a6a1aa8e4f79fc9424b16dd9a3902d2eb4d (patch)
tree8c6f40c4589469b77e7a083a3865b29ae2c92b7b /src
parentfix issue #2 (diff)
downloadslibc-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')
-rw-r--r--src/unistd/execat.c10
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;
}