aboutsummaryrefslogtreecommitdiff
path: root/ex.c
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2021-07-08 09:40:23 +0000
committerOmar Polo <op@omarpolo.com>2021-07-08 09:40:23 +0000
commite7c6502bf3ebe199349e315ac7f112db6a2db38e (patch)
tree7fffa74c0596a1bc1c8f6f1cd9ecf36701bbfb8b /ex.c
parenta8a1f439210de9538b196c6bb5470c306379128c (diff)
don't leak a file descriptor
make sure we always close every fd in every possible code path; while there, also add a log_err if fork(2) failed.
Diffstat (limited to 'ex.c')
-rw-r--r--ex.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/ex.c b/ex.c
index 8e25bd1..cad8d9a 100644
--- a/ex.c
+++ b/ex.c
@@ -137,6 +137,11 @@ launch_cgi(struct iri *iri, struct cgireq *req, struct vhost *vhost,
switch (fork()) {
case -1:
+ log_err(NULL, "fork failed: %s", strerror(errno));
+ close(p[0]);
+ close(p[1]);
+ close(errp[0]);
+ close(errp[1]);
return -1;
case 0: { /* child */
@@ -230,6 +235,7 @@ launch_cgi(struct iri *iri, struct cgireq *req, struct vhost *vhost,
default:
close(p[1]);
+ close(errp[0]);
close(errp[1]);
mark_nonblock(p[0]);
return p[0];