X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Futils_ignorelist.c;h=b8169ff656483a3d2e7c55c45a4cea2853d7dad2;hb=ab2e3c958d3fed41438a8b3c2d0cca21b1bca56f;hp=94d6bdae7c92a5989149fb2ce73e0b3a62e4ecec;hpb=5aac2498eeacce2ab28302bca2103960a11474f7;p=collectd.git diff --git a/src/utils_ignorelist.c b/src/utils_ignorelist.c index 94d6bdae..b8169ff6 100644 --- a/src/utils_ignorelist.c +++ b/src/utils_ignorelist.c @@ -1,6 +1,7 @@ /** * collectd - src/utils_ignorelist.c * Copyright (C) 2006 Lubos Stanek + * Copyright (C) 2008 Florian Forster * * This program is free software; you can redistribute it and/ * or modify it under the terms of the GNU General Public Li- @@ -19,6 +20,7 @@ * * Authors: * Lubos Stanek + * Florian Forster **/ /** * ignorelist handles plugin's list of configured collectable @@ -129,6 +131,7 @@ static int ignorelist_append_regex(ignorelist_t *il, const char *entry) if (errsize) sfree (regerr); regfree (regtemp); + sfree (regtemp); return (1); } DEBUG("regex compiled: %s - %i", entry, rcompile); @@ -138,6 +141,7 @@ static int ignorelist_append_regex(ignorelist_t *il, const char *entry) { ERROR ("cannot allocate new config entry"); regfree (regtemp); + sfree (regtemp); return (1); } memset (new, '\0', sizeof(ignorelist_item_t)); @@ -246,6 +250,7 @@ void ignorelist_free (ignorelist_t *il) if (this->rmatch != NULL) { regfree (this->rmatch); + sfree (this->rmatch); this->rmatch = NULL; } #endif @@ -304,11 +309,12 @@ int ignorelist_add (ignorelist_t *il, const char *entry) if ((entry_len > 2) && (entry[0] == '/') && entry[entry_len - 1] == '/') { char *entry_copy; + size_t entry_copy_size; /* We need to copy `entry' since it's const */ - entry_copy = smalloc (entry_len); - memset (entry_copy, '\0', entry_len); - strncpy (entry_copy, entry + 1, entry_len - 2); + entry_copy_size = entry_len - 1; + entry_copy = smalloc (entry_copy_size); + sstrncpy (entry_copy, entry + 1, entry_copy_size); DEBUG("I'm about to add regex entry: %s", entry_copy); ret = ignorelist_append_regex(il, entry_copy); @@ -332,10 +338,8 @@ int ignorelist_match (ignorelist_t *il, const char *entry) { ignorelist_item_t *traverse; - assert (il != NULL); - /* if no entries, collect all */ - if (il->head == NULL) + if ((il == NULL) || (il->head == NULL)) return (0); if ((entry == NULL) || (strlen (entry) == 0))