summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGuillem Jover <guillem@hadrons.org>2015-09-24 04:01:11 +0200
committerGuillem Jover <guillem@hadrons.org>2015-09-24 05:28:58 +0200
commit8641d8aed711f74179915fe2fde89c9969ff7de4 (patch)
tree6a4846574c654387994ba1bae1009538fc4db0b1 /src
parent0982dcd98b7561269fdddaef4388da7177de7603 (diff)
Make closefrom_procfs() fail when reallocarray() fails
Diffstat (limited to 'src')
-rw-r--r--src/closefrom.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/closefrom.c b/src/closefrom.c
index b6d9834..c2922e7 100644
--- a/src/closefrom.c
+++ b/src/closefrom.c
@@ -132,6 +132,7 @@ closefrom_procfs(int lowfd)
int *fd_array = NULL;
int fd_array_used = 0;
int fd_array_size = 0;
+ int ret = 0;
int i;
/* Use /proc/self/fd (or /dev/fd on FreeBSD) if it exists. */
@@ -161,8 +162,10 @@ closefrom_procfs(int lowfd)
fd_array_size = 32;
ptr = reallocarray(fd_array, fd_array_size, sizeof(int));
- if (ptr == NULL)
+ if (ptr == NULL) {
+ ret = -1;
break;
+ }
fd_array = ptr;
}
@@ -175,7 +178,7 @@ closefrom_procfs(int lowfd)
free(fd_array);
(void)closedir(dirp);
- return 0;
+ return ret;
}
void