If fork fails in getOutputFrom(), close opened unused pipe fds on error code path

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
This commit is contained in:
Denys Vlasenko 2020-01-23 14:21:26 +01:00 committed by Florian Festi
parent d937b04fb1
commit 83a5a20352
1 changed files with 11 additions and 5 deletions

View File

@ -277,6 +277,17 @@ static int getOutputFrom(ARGV_t argv,
}
child = fork();
if (child < 0) {
rpmlog(RPMLOG_ERR, _("Couldn't fork %s: %s\n"),
argv[0], strerror(errno));
if (doio) {
close(toProg[1]);
close(toProg[0]);
close(fromProg[0]);
close(fromProg[1]);
}
return -1;
}
if (child == 0) {
close(toProg[1]);
close(fromProg[0]);
@ -299,11 +310,6 @@ static int getOutputFrom(ARGV_t argv,
argv[0], strerror(errno));
_exit(EXIT_FAILURE);
}
if (child < 0) {
rpmlog(RPMLOG_ERR, _("Couldn't fork %s: %s\n"),
argv[0], strerror(errno));
return -1;
}
if (!doio)
goto reap;