]> git.meshlink.io Git - meshlink/commitdiff
Fix a memory leak.
authorGuus Sliepen <guus@meshlink.io>
Thu, 8 Apr 2021 20:09:45 +0000 (22:09 +0200)
committerGuus Sliepen <guus@meshlink.io>
Thu, 8 Apr 2021 20:09:45 +0000 (22:09 +0200)
src/net_packet.c
src/netutl.c

index ce1eb62680bd1c25fcb2038dc50892069ab21cce..02a617d1922bfae065a41539b14ddedec707964e 100644 (file)
@@ -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);
index 2dcf1e47ead24a3b9ac630a87c6c7f103747772b..79dadea529beb918bbbdbe7500f503e393d2b664 100644 (file)
@@ -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;
        }