From c99339abe31cf11172fe5f903d70884336272513 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Tue, 20 Nov 2018 15:58:41 +0100 Subject: [PATCH] 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. --- src/meshlink.c | 4 ++++ 1 file changed, 4 insertions(+) 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; } -- 2.39.5