X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdaemon%2Futils_ignorelist.c;h=ff73ad74a4b3ed2cfb9690710fe917902778bd3c;hb=4979d8dcd6f097eb8fd4661086e28accd31ff905;hp=12688380e89739f9afd03e6440521580cf5fe74d;hpb=17b60946497048b34b417aa0497607f3aa6a34f3;p=collectd.git diff --git a/src/daemon/utils_ignorelist.c b/src/daemon/utils_ignorelist.c index 12688380..ff73ad74 100644 --- a/src/daemon/utils_ignorelist.c +++ b/src/daemon/utils_ignorelist.c @@ -27,7 +27,7 @@ **/ /** * Usage: - * + * * Define plugin's global pointer variable of type ignorelist_t: * ignorelist_t *myconfig_ignore; * If you know the state of the global ignore (IgnoreSelected), @@ -94,13 +94,12 @@ static int ignorelist_append_regex(ignorelist_t *il, const char *re_str) ignorelist_item_t *entry; int status; - re = malloc (sizeof (*re)); + re = calloc (1, sizeof (*re)); if (re == NULL) { - ERROR ("ignorelist_append_regex: malloc failed."); + ERROR ("ignorelist_append_regex: calloc failed."); return (ENOMEM); } - memset (re, 0, sizeof (*re)); status = regcomp (re, re_str, REG_EXTENDED); if (status != 0) @@ -113,15 +112,14 @@ static int ignorelist_append_regex(ignorelist_t *il, const char *re_str) return (status); } - entry = malloc (sizeof (*entry)); + entry = calloc (1, sizeof (*entry)); if (entry == NULL) { - ERROR ("ignorelist_append_regex: malloc failed."); + ERROR ("ignorelist_append_regex: calloc failed."); regfree (re); sfree (re); return (ENOMEM); } - memset (entry, 0, sizeof (*entry)); entry->rmatch = re; ignorelist_append (il, entry); @@ -134,12 +132,11 @@ static int ignorelist_append_string(ignorelist_t *il, const char *entry) ignorelist_item_t *new; /* create new entry */ - if ((new = malloc(sizeof(ignorelist_item_t))) == NULL ) + if ((new = calloc(1, sizeof (*new))) == NULL ) { ERROR ("cannot allocate new entry"); return (1); } - memset (new, '\0', sizeof(ignorelist_item_t)); new->smatch = sstrdup(entry); /* append new entry */ @@ -194,10 +191,9 @@ ignorelist_t *ignorelist_create (int invert) { ignorelist_t *il; - il = malloc (sizeof (*il)); + il = calloc (1, sizeof (*il)); if (il == NULL) return NULL; - memset (il, 0, sizeof (*il)); /* * ->ignore == 0 => collect @@ -239,7 +235,6 @@ void ignorelist_free (ignorelist_t *il) } sfree (il); - il = NULL; } /* void ignorelist_destroy (ignorelist_t *il) */ /* @@ -309,8 +304,6 @@ int ignorelist_add (ignorelist_t *il, const char *entry) */ int ignorelist_match (ignorelist_t *il, const char *entry) { - ignorelist_item_t *traverse; - /* if no entries, collect all */ if ((il == NULL) || (il->head == NULL)) return (0); @@ -319,7 +312,7 @@ int ignorelist_match (ignorelist_t *il, const char *entry) return (0); /* traverse list and check entries */ - for (traverse = il->head; traverse != NULL; traverse = traverse->next) + for (ignorelist_item_t *traverse = il->head; traverse != NULL; traverse = traverse->next) { #if HAVE_REGEX_H if (traverse->rmatch != NULL)