rpm/backport-If-fork-fails-in-getOutputFrom-close-opened-unused-p.patch

49 lines
1.2 KiB
Diff
Raw Normal View History

2021-01-11 11:10:36 +08:00
From 83a5a20352dccd336a0114238c5988f0a9fa6d3e Mon Sep 17 00:00:00 2001
From: Denys Vlasenko <dvlasenk@redhat.com>
Date: Thu, 23 Jan 2020 14:21:26 +0100
Subject: [PATCH] If fork fails in getOutputFrom(), close opened unused pipe
fds on error code path
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
---
build/rpmfc.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/build/rpmfc.c b/build/rpmfc.c
index f5f3793b9..81101518b 100644
--- a/build/rpmfc.c
+++ b/build/rpmfc.c
@@ -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;
--
2.27.0