From 4e354adcee4724222798644906c04f084ecfa67a Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 2 Aug 2022 18:48:52 +0200 Subject: [PATCH] utils: fix memory leak in network_get_endpoint() Signed-off-by: Felix Fietkau --- utils.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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; -- 2.30.2