From 730bb4a28b4970aa05586b1c02be7420cd491462 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Thu, 8 Apr 2021 22:09:45 +0200 Subject: [PATCH] Fix a memory leak. --- src/net_packet.c | 7 +++++-- src/netutl.c | 5 ++--- 2 files changed, 7 insertions(+), 5 deletions(-) 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; } -- 2.39.5