]> git.ipfire.org Git - thirdparty/libbsd.git/commitdiff
Make closefrom_procfs() fail when reallocarray() fails
authorGuillem Jover <guillem@hadrons.org>
Thu, 24 Sep 2015 02:01:11 +0000 (04:01 +0200)
committerGuillem Jover <guillem@hadrons.org>
Thu, 24 Sep 2015 03:28:58 +0000 (05:28 +0200)
src/closefrom.c

index b6d983486b4456f68ce8930b84f66dc191a729cc..c2922e716b1c86dbb8355f650dd5b934c5e6947e 100644 (file)
@@ -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