diff options
author | Don Lewis <truckman@FreeBSD.org> | 2016-05-25 07:13:53 +0000 |
---|---|---|
committer | Don Lewis <truckman@FreeBSD.org> | 2016-05-25 07:13:53 +0000 |
commit | 9b842193f9474f5a9027944099e85ab76479a9d4 (patch) | |
tree | c4b7bd3e0df35c338013b111eba33bd975ad3f72 /lib | |
parent | 015f4df218bdc19f28320e7ff55bdb85cf67b8a0 (diff) | |
download | src-9b842193f9474f5a9027944099e85ab76479a9d4.tar.gz src-9b842193f9474f5a9027944099e85ab76479a9d4.zip |
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
MFC after: 1 week
Notes
Notes:
svn path=/head/; revision=300662
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/gen/posix_spawn.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/libc/gen/posix_spawn.c b/lib/libc/gen/posix_spawn.c index c65a730875d2..2838c5c0aacd 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); |