utils: fix memory leak in network_get_endpoint()
authorFelix Fietkau <nbd@nbd.name>
Tue, 2 Aug 2022 16:48:52 +0000 (18:48 +0200)
committerFelix Fietkau <nbd@nbd.name>
Tue, 2 Aug 2022 16:53:49 +0000 (18:53 +0200)
Signed-off-by: Felix Fietkau <nbd@nbd.name>
utils.c

diff --git a/utils.c b/utils.c
index 462ebbf15108b6171d27482d2087d60dbe8e9c5f..ccbc6ed828d6e437597238063fa1a8f94b6235d2 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -27,7 +27,7 @@ int network_get_endpoint(union network_endpoint *dest, const char *str,
                host++;
                port = strchr(host, ']');
                if (!port)
-                       return -1;
+                       goto out;
 
                *(port++) = 0;
                if (!*port)
@@ -60,13 +60,16 @@ int network_get_endpoint(union network_endpoint *dest, const char *str,
 
 found:
        if (ai_cur->ai_addrlen > sizeof(*dest))
-               goto out;
+               goto free_ai;
 
        memcpy(dest, ai_cur->ai_addr, ai_cur->ai_addrlen);
        if (!port)
                dest->in.sin_port = htons(default_port);
        ret = 0;
 
+free_ai:
+       freeaddrinfo(ai_cur);
+
 out:
        free(buf);
        return ret;