From: Felix Fietkau Date: Tue, 2 Aug 2022 16:48:52 +0000 (+0200) Subject: utils: fix memory leak in network_get_endpoint() X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=4e354adcee4724222798644906c04f084ecfa67a;p=project%2Funetd.git utils: fix memory leak in network_get_endpoint() Signed-off-by: Felix Fietkau --- diff --git a/utils.c b/utils.c index 462ebbf..ccbc6ed 100644 --- 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;