mirror of
https://gitlab.freedesktop.org/libbsd/libbsd.git
synced 2025-04-21 09:00:26 +02:00
Make closefrom_procfs() fail when reallocarray() fails
This commit is contained in:
parent
0982dcd98b
commit
8641d8aed7
@ -132,6 +132,7 @@ closefrom_procfs(int lowfd)
|
|||||||
int *fd_array = NULL;
|
int *fd_array = NULL;
|
||||||
int fd_array_used = 0;
|
int fd_array_used = 0;
|
||||||
int fd_array_size = 0;
|
int fd_array_size = 0;
|
||||||
|
int ret = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Use /proc/self/fd (or /dev/fd on FreeBSD) if it exists. */
|
/* Use /proc/self/fd (or /dev/fd on FreeBSD) if it exists. */
|
||||||
@ -161,8 +162,10 @@ closefrom_procfs(int lowfd)
|
|||||||
fd_array_size = 32;
|
fd_array_size = 32;
|
||||||
|
|
||||||
ptr = reallocarray(fd_array, fd_array_size, sizeof(int));
|
ptr = reallocarray(fd_array, fd_array_size, sizeof(int));
|
||||||
if (ptr == NULL)
|
if (ptr == NULL) {
|
||||||
|
ret = -1;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
fd_array = ptr;
|
fd_array = ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +178,7 @@ closefrom_procfs(int lowfd)
|
|||||||
free(fd_array);
|
free(fd_array);
|
||||||
(void)closedir(dirp);
|
(void)closedir(dirp);
|
||||||
|
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user