From 2a1a7a6a1aa8e4f79fc9424b16dd9a3902d2eb4d Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 19 Nov 2015 22:33:16 +0100 Subject: fix memory leak at failure of execveat (issue #3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/unistd/execat.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') 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; } -- cgit v1.2.3-70-g09d2