[Libwebsockets] getaddrinfo memory leak

Andy Green andy at warmcat.com
Sat Apr 11 01:10:56 CEST 2015



On 11 April 2015 01:59:21 GMT+08:00, Danomi Czaski <djczaski at gmail.com> wrote:
>Valgrind complains of a small memory leak from getaddrinfo when
>creating connections. The following patch seems to fix it:

Ah... nice job thanks.  It's pushed.

http://git.libwebsockets.org/cgi-bin/cgit/libwebsockets/commit/?id=7fb366a9ef6d232699a3066882a031fb212a7b43

-Andy

>diff --git a/lib/client-handshake.c b/lib/client-handshake.c
>index 40916d6..7169058 100644
>--- a/lib/client-handshake.c
>+++ b/lib/client-handshake.c
>@@ -96,7 +96,7 @@ struct libwebsocket *libwebsocket_client_connect_2(
>        } else
> #endif
>        {
>-               struct addrinfo ai, *res;
>+               struct addrinfo ai, *res, *result;
>                void *p = NULL;
>
>                memset (&ai, 0, sizeof ai);
>@@ -104,9 +104,10 @@ struct libwebsocket
>*libwebsocket_client_connect_2(
>                ai.ai_socktype = SOCK_STREAM;
>                ai.ai_flags = AI_CANONNAME;
>
>-               if (getaddrinfo(ads, NULL, &ai, &res))
>+               if (getaddrinfo(ads, NULL, &ai, &result))
>                        goto oom4;
>
>+               res = result;
>                while (!p && res) {
>                        switch (res->ai_family) {
>                        case AF_INET:
>@@ -118,11 +119,15 @@ struct libwebsocket
>*libwebsocket_client_connect_2(
>                }
>
>                if (!p)
>+               {
>+                       freeaddrinfo(result);
>                        goto oom4;
>+               }
>
>                server_addr4.sin_family = AF_INET;
>                server_addr4.sin_addr = *((struct in_addr *)p);
>                bzero(&server_addr4.sin_zero, 8);
>+               freeaddrinfo(result);
>        }
>
>        if (wsi->sock < 0) {
>_______________________________________________
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org
>http://ml.libwebsockets.org/mailman/listinfo/libwebsockets




More information about the Libwebsockets mailing list