summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authortruckman <truckman@FreeBSD.org>2016-06-01 17:39:03 +0000
committertruckman <truckman@FreeBSD.org>2016-06-01 17:39:03 +0000
commitfa7d0f23a5adc1d2f858496ce03e3c066f8a0e91 (patch)
tree29e1fa3d0a3c80f02ea6aceb0ba60696fbdb2edc /lib
parentc8f45181287c0cd144f51bd035b3dd26f633a2b2 (diff)
downloadFreeBSD-src-fa7d0f23a5adc1d2f858496ce03e3c066f8a0e91.zip
FreeBSD-src-fa7d0f23a5adc1d2f858496ce03e3c066f8a0e91.tar.gz
MFC r300662
Fix Coverity CID 1016714 Resource leak in process_file_actions_entry() Don't leak a file descriptor of _dup2() fails (shouldn't happen). Reported by: Coverity CID: 1016714
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/gen/posix_spawn.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/libc/gen/posix_spawn.c b/lib/libc/gen/posix_spawn.c
index c65a730..2838c5c 100644
--- a/lib/libc/gen/posix_spawn.c
+++ b/lib/libc/gen/posix_spawn.c
@@ -140,7 +140,7 @@ process_spawnattr(const posix_spawnattr_t sa)
static int
process_file_actions_entry(posix_spawn_file_actions_entry_t *fae)
{
- int fd;
+ int fd, saved_errno;
switch (fae->fae_action) {
case FAE_OPEN:
@@ -149,8 +149,11 @@ process_file_actions_entry(posix_spawn_file_actions_entry_t *fae)
if (fd < 0)
return (errno);
if (fd != fae->fae_fildes) {
- if (_dup2(fd, fae->fae_fildes) == -1)
- return (errno);
+ if (_dup2(fd, fae->fae_fildes) == -1) {
+ saved_errno = errno;
+ (void)_close(fd);
+ return (saved_errno);
+ }
if (_close(fd) != 0) {
if (errno == EBADF)
return (EBADF);
OpenPOWER on IntegriCloud