Browse code

Close any open FDs prior to returning from the function under an error condition

Shawn Webb authored on 2014/01/31 00:55:05
Showing 1 changed files
... ...
@@ -85,6 +85,9 @@ int tcpserver(int **lsockets, unsigned int *nlsockets, char *ipaddr, const struc
85 85
     for (p = info; p != NULL; p = p->ai_next, i++) {
86 86
         t = realloc(sockets, sizeof(int) * (*nlsockets + 1));
87 87
         if (!(t)) {
88
+            for (i=0; i < *nlsockets; i++)
89
+                close(sockets[i]);
90
+
88 91
             return -1;
89 92
         }
90 93
         sockets = t;