From 9d208c24c0cc42562a09ea7ea145642b3bca29dc Mon Sep 17 00:00:00 2001 From: elieyal <17270807+elieyal@users.noreply.github.com> Date: Wed, 20 Jun 2018 17:32:40 +0300 Subject: [PATCH] Fixed leak and hint Added suggested fixes --- src/network.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/network.c b/src/network.c index 0fdb1c0e..687717c4 100644 --- a/src/network.c +++ b/src/network.c @@ -2738,16 +2738,17 @@ network_config_set_bind_address(const oconfig_item_t *ci, return -1; int ret; - struct addrinfo hint, *res = NULL; - - memset(&hint, '\0', sizeof hint); - hint.ai_family = PF_UNSPEC; - hint.ai_flags = AI_NUMERICHOST; + struct addrinfo *res = NULL; + struct addrinfo hint = {.ai_family = PF_UNSPEC, + .ai_flags = AI_NUMERICHOST, + .ai_protocol = IPPROTO_IP, + .ai_socktype = SOCK_DGRAM}; ret = getaddrinfo(addr_text, NULL, &hint, &res); if (ret) { ERROR("network plugin: Bind address option has invalid address set: %s", gai_strerror(ret)); + freeaddrinfo(res); return -1; } @@ -2763,9 +2764,11 @@ network_config_set_bind_address(const oconfig_item_t *ci, ERROR("network plugin: %s is an unknown address format %d\n", addr_text, res->ai_family); sfree(*bind_address); + freeaddrinfo(res); return -1; } + freeaddrinfo(res); return 0; } /* int network_config_set_bind_address */ -- 2.11.0