From: Florian Forster Date: Fri, 19 Jun 2015 08:54:02 +0000 (+0200) Subject: powerdns plugin: Fix memory leak. X-Git-Tag: collectd-5.5.1~68^2~26 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=78154d2a5ae84e8f45d4f9ce6a7519add74b4b30;p=collectd.git powerdns plugin: Fix memory leak. While at it, replace the powerdns_config_add_string() function. --- diff --git a/src/powerdns.c b/src/powerdns.c index 11974aaa..c8e72cbf 100644 --- a/src/powerdns.c +++ b/src/powerdns.c @@ -722,25 +722,6 @@ static int powerdns_read_recursor (list_item_t *item) /* {{{ */ return (0); } /* }}} int powerdns_read_recursor */ -static int powerdns_config_add_string (const char *name, /* {{{ */ - char **dest, - oconfig_item_t *ci) -{ - if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) - { - WARNING ("powerdns plugin: `%s' needs exactly one string argument.", - name); - return (-1); - } - - sfree (*dest); - *dest = strdup (ci->values[0].value.string); - if (*dest == NULL) - return (-1); - - return (0); -} /* }}} int powerdns_config_add_string */ - static int powerdns_config_add_collect (list_item_t *li, /* {{{ */ oconfig_item_t *ci) { @@ -851,7 +832,7 @@ static int powerdns_config_add_server (oconfig_item_t *ci) /* {{{ */ if (strcasecmp ("Collect", option->key) == 0) status = powerdns_config_add_collect (item, option); else if (strcasecmp ("Socket", option->key) == 0) - status = powerdns_config_add_string ("Socket", &socket_temp, option); + status = cf_util_get_string (option, &socket_temp); else { ERROR ("powerdns plugin: Option `%s' not allowed here.", option->key); @@ -891,12 +872,14 @@ static int powerdns_config_add_server (oconfig_item_t *ci) /* {{{ */ if (status != 0) { + sfree (socket_temp); sfree (item); return (-1); } DEBUG ("powerdns plugin: Add server: instance = %s;", item->instance); + sfree (socket_temp); return (0); } /* }}} int powerdns_config_add_server */