Fixed leakage of pipe descriptors in case of failing fork
This commit is contained in:
parent
ed030fe4d3
commit
51854c6148
18
main.c
18
main.c
|
@ -262,20 +262,22 @@ void open_info(void)
|
||||||
|
|
||||||
if (pipe(pfd) < 0)
|
if (pipe(pfd) < 0)
|
||||||
return;
|
return;
|
||||||
pid = fork();
|
if ((pid = fork()) == 0) {
|
||||||
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) {
|
|
||||||
close(pfd[0]);
|
close(pfd[0]);
|
||||||
dup2(pfd[1], 1);
|
dup2(pfd[1], 1);
|
||||||
execl(info.cmd, info.cmd, files[fileidx].name, NULL);
|
execl(info.cmd, info.cmd, files[fileidx].name, NULL);
|
||||||
warn("could not exec: %s", info.cmd);
|
warn("could not exec: %s", info.cmd);
|
||||||
exit(EXIT_FAILURE);
|
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)
|
void read_info(void)
|
||||||
|
|
Loading…
Reference in New Issue