From: Guus Sliepen Date: Tue, 20 Nov 2018 14:58:41 +0000 (+0100) Subject: Fix socket leak every time meshlink_invite() is called. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=c99339abe31cf11172fe5f903d70884336272513;p=meshlink Fix socket leak every time meshlink_invite() is called. getlocaladdrname() would leak a socket every time it was called, which is twice for every call to meshlink_invite() using the default flags. --- diff --git a/src/meshlink.c b/src/meshlink.c index 8da56922..1bb403f3 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -226,6 +226,7 @@ static bool getlocaladdrname(char *destaddr, char *host, socklen_t hostlen) { } if(connect(sock, rai->ai_addr, rai->ai_addrlen) && !sockwouldblock(errno)) { + closesocket(sock); freeaddrinfo(rai); return false; } @@ -236,9 +237,12 @@ static bool getlocaladdrname(char *destaddr, char *host, socklen_t hostlen) { socklen_t sl = sizeof(sn); if(getsockname(sock, (struct sockaddr *)&sn, &sl)) { + closesocket(sock); return false; } + closesocket(sock); + if(getnameinfo((struct sockaddr *)&sn, sl, host, hostlen, NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV)) { return false; }