mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-21 11:13:30 +00:00
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
This commit is contained in:
parent
015f4df218
commit
9b842193f9
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=300662
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user