From: elieyal <17270807+elieyal@users.noreply.github.com> Date: Wed, 20 Jun 2018 14:32:40 +0000 (+0300) Subject: Fixed leak and hint X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=9d208c24c0cc42562a09ea7ea145642b3bca29dc;p=collectd.git Fixed leak and hint Added suggested fixes --- 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 */