From: Guus Sliepen Date: Thu, 8 Apr 2021 20:09:45 +0000 (+0200) Subject: Fix a memory leak. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=730bb4a28b4970aa05586b1c02be7420cd491462;p=meshlink Fix a memory leak. --- diff --git a/src/net_packet.c b/src/net_packet.c index ce1eb626..02a617d1 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -339,8 +339,11 @@ static void choose_udp_address(meshlink_handle_t *mesh, const node_t *n, const s *port++ = 0; *sa_buf = str2sockaddr_random(mesh, host, port); *sa = sa_buf; - free(host); - goto check_socket; + + if(sa_buf->sa.sa_family != AF_UNKNOWN) { + free(host); + goto check_socket; + } } free(host); diff --git a/src/netutl.c b/src/netutl.c index 2dcf1e47..79dadea5 100644 --- a/src/netutl.c +++ b/src/netutl.c @@ -94,10 +94,9 @@ sockaddr_t str2sockaddr_random(struct meshlink_handle *mesh, const char *address err = getaddrinfo(address, port, &hint, &ai); if(err || !ai) { - logger(NULL, MESHLINK_DEBUG, "Unknown type address %s port %s", address, port); result.sa.sa_family = AF_UNKNOWN; - result.unknown.address = xstrdup(address); - result.unknown.port = xstrdup(port); + result.unknown.address = NULL; + result.unknown.port = NULL; return result; }