summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBert Münnich <ber.t@posteo.de>2014-11-27 22:25:27 +0100
committerBert Münnich <ber.t@posteo.de>2014-11-27 22:25:27 +0100
commit51854c614873f59571e80da79f0dc0e8446cbf21 (patch)
tree0dbf8fd0ba17923e24a663893619783eb2f86612
parented030fe4d38f74893739c99dc27f323172218d28 (diff)
downloadnsxiv-51854c614873f59571e80da79f0dc0e8446cbf21.tar.zst
Fixed leakage of pipe descriptors in case of failing fork
-rw-r--r--main.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/main.c b/main.c
index fcbab7d..f8dbab8 100644
--- a/main.c
+++ b/main.c
@@ -262,20 +262,22 @@ void open_info(void)
if (pipe(pfd) < 0)
return;
- pid = fork();
- if (pid > 0) {
- close(pfd[1]);
- fcntl(pfd[0], F_SETFL, O_NONBLOCK);
- info.fd = pfd[0];
- info.i = info.lastsep = 0;
- info.open = true;
- } else if (pid == 0) {
+ if ((pid = fork()) == 0) {
close(pfd[0]);
dup2(pfd[1], 1);
execl(info.cmd, info.cmd, files[fileidx].name, NULL);
warn("could not exec: %s", info.cmd);
exit(EXIT_FAILURE);
}
+ close(pfd[1]);
+ if (pid < 0) {
+ close(pfd[0]);
+ } else {
+ fcntl(pfd[0], F_SETFL, O_NONBLOCK);
+ info.fd = pfd[0];
+ info.i = info.lastsep = 0;
+ info.open = true;
+ }
}
void read_info(void)