From: Ruben Kerkhof Date: Sat, 25 Jul 2015 17:17:07 +0000 (+0200) Subject: Fix some small leaks on error paths X-Git-Tag: collectd-5.5.1~68^2~8 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=00b6ce0313875d10ad0969a4c0169df0cddd8183;p=collectd.git Fix some small leaks on error paths --- diff --git a/src/collectd-nagios.c b/src/collectd-nagios.c index e31d95ca..7fda6fc1 100644 --- a/src/collectd-nagios.c +++ b/src/collectd-nagios.c @@ -303,8 +303,7 @@ static int do_listval (lcc_connection_t *connection) if ((hostname == NULL) || strcasecmp (hostname, ret_ident[i].host)) { - if (hostname != NULL) - free (hostname); + free (hostname); hostname = strdup (ret_ident[i].host); printf ("Host: %s\n", hostname); } @@ -318,6 +317,8 @@ static int do_listval (lcc_connection_t *connection) printf ("ERROR: listval: Failed to convert returned " "identifier to a string: %s\n", lcc_strerror (connection)); + free (hostname); + hostname = NULL; continue; } @@ -325,8 +326,8 @@ static int do_listval (lcc_connection_t *connection) printf ("\t%s\n", id + 1); } - if (ret_ident != NULL) - free (ret_ident); + free (ret_ident); + free (hostname); return (RET_OKAY); } /* int do_listval */ diff --git a/src/collectd.c b/src/collectd.c index 6815cccf..1ccc1c08 100644 --- a/src/collectd.c +++ b/src/collectd.c @@ -182,8 +182,10 @@ static int change_basedir (const char *orig_dir) while ((dirlen > 0) && (dir[dirlen - 1] == '/')) dir[--dirlen] = '\0'; - if (dirlen <= 0) + if (dirlen <= 0) { + free (dir); return (-1); + } status = chdir (dir); if (status == 0) diff --git a/src/configfile.c b/src/configfile.c index c389ad16..32629e08 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -610,8 +610,11 @@ static int cf_include_all (oconfig_item_t *root, int depth) return (-1); /* Now replace the i'th child in `root' with `new'. */ - if (cf_ci_replace_child (root, new, i) < 0) + if (cf_ci_replace_child (root, new, i) < 0) { + sfree (new->values); + sfree (new); return (-1); + } /* ... and go back to the new i'th child. */ --i; diff --git a/src/iptables.c b/src/iptables.c index 49454f05..606b24d9 100644 --- a/src/iptables.c +++ b/src/iptables.c @@ -213,6 +213,7 @@ static int iptables_config (const char *key, const char *value) char errbuf[1024]; ERROR ("realloc failed: %s", sstrerror (errno, errbuf, sizeof (errbuf))); + sfree (temp.rule.comment); return (1); } @@ -223,6 +224,7 @@ static int iptables_config (const char *key, const char *value) char errbuf[1024]; ERROR ("malloc failed: %s", sstrerror (errno, errbuf, sizeof (errbuf))); + sfree (temp.rule.comment); return (1); } memcpy (final, &temp, sizeof (temp)); diff --git a/src/utils_cache.c b/src/utils_cache.c index 7eae1c7e..910e30b2 100644 --- a/src/utils_cache.c +++ b/src/utils_cache.c @@ -191,6 +191,7 @@ static int uc_insert (const data_set_t *ds, const value_list_t *vl, /* This shouldn't happen. */ ERROR ("uc_insert: Don't know how to handle data source type %i.", ds->ds[i].type); + sfree (key_copy); return (-1); } /* switch (ds->ds[i].type) */ } /* for (i) */