From: Florian Forster Date: Fri, 19 Jun 2015 08:54:02 +0000 (+0200) Subject: gmond plugin: Fix memory leak. X-Git-Tag: collectd-5.5.1~68^2~30 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=d0a7578e52cbe8b6222cc2ef48273322db963205;p=collectd.git gmond plugin: Fix memory leak. --- diff --git a/src/gmond.c b/src/gmond.c index ff4936d1..7c9028a1 100644 --- a/src/gmond.c +++ b/src/gmond.c @@ -217,13 +217,13 @@ static int create_sockets (socket_entry_t **ret_sockets, /* {{{ */ struct addrinfo *ai_ptr; int ai_return; - socket_entry_t *sockets; - size_t sockets_num; + socket_entry_t *sockets = NULL; + size_t sockets_num = 0; int status; - - sockets = *ret_sockets; - sockets_num = *ret_sockets_num; + + if (*ret_sockets != NULL) + return (EINVAL); memset (&ai_hints, 0, sizeof (ai_hints)); ai_hints.ai_flags = 0; @@ -355,8 +355,11 @@ static int create_sockets (socket_entry_t **ret_sockets, /* {{{ */ freeaddrinfo (ai_list); - if ((*ret_sockets_num) >= sockets_num) + if (sockets_num == 0) + { + sfree (sockets); return (-1); + } *ret_sockets = sockets; *ret_sockets_num = sockets_num;