Memleak: getaddrinfo needs freeadrinfo here too.
authorWilfried Goesgens <dothebart@citadel.org>
Sun, 28 Nov 2010 20:02:00 +0000 (21:02 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 28 Nov 2010 20:02:00 +0000 (21:02 +0100)
webcit/tcp_sockets.c

index 99173ea518771aef130267864d561639112ec5d6..2ee3cb27e0b81e0289c766cdc70eadf97d1797a3 100644 (file)
@@ -110,6 +110,7 @@ int tcp_connectsock(char *host, char *service)
        rc = getaddrinfo(host, service, &hints, &res);
        if (rc != 0) {
                lprintf(1, "%s: %s\n", host, gai_strerror(rc));
+               freeaddrinfo(res);
                return(-1);
        }
 
@@ -125,10 +126,12 @@ int tcp_connectsock(char *host, char *service)
                s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
                if (s < 0) {
                        lprintf(1, "socket() failed: %s\n", strerror(errno));
+                       freeaddrinfo(res);
                        return(-1);
                }
                rc = connect(s, ai->ai_addr, ai->ai_addrlen);
                if (rc >= 0) {
+                       freeaddrinfo(res);
                        return(s);
                }
                else {
@@ -136,7 +139,7 @@ int tcp_connectsock(char *host, char *service)
                        close(s);
                }
        }
-
+        freeaddrinfo(res);
        return(-1);
 }