Try to use FD_CLOEXEC instead of mass-closing everywhere.
[ashd.git] / lib / req.c
index 7bb37b4..a3e7273 100644 (file)
--- a/lib/req.c
+++ b/lib/req.c
@@ -23,6 +23,7 @@
 #include <errno.h>
 #include <ctype.h>
 #include <stdio.h>
+#include <fcntl.h>
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -200,7 +201,7 @@ void headrmheader(struct hthead *head, const char *name)
            free(head->headers[i][0]);
            free(head->headers[i][1]);
            free(head->headers[i]);
-           memmove(head->headers + i, head->headers + i + 1, --head->noheaders - i);
+           memmove(head->headers + i, head->headers + i + 1, sizeof(head->headers) * (--head->noheaders - i));
            return;
        }
     }
@@ -254,6 +255,7 @@ int recvreq(int sock, struct hthead **reqp)
     if((fd = recvfd(sock, &buf.b, &buf.d)) < 0) {
        return(-1);
     }
+    fcntl(fd, F_SETFD, FD_CLOEXEC);
     buf.s = buf.d;
     p = buf.b;
     l = buf.d;