Merge branch 'collectd-5.4' into collectd-5.5
[collectd.git] / src / utils_ignorelist.c
index 518715b..7b1c7d2 100644 (file)
@@ -1,7 +1,7 @@
 /**
  * collectd - src/utils_ignorelist.c
  * Copyright (C) 2006 Lubos Stanek <lubek at users.sourceforge.net>
- * Copyright (C) 2008 Florian Forster <octo at verplant.org>
+ * Copyright (C) 2008 Florian Forster <octo at collectd.org>
  *
  * This program is free software; you can redistribute it and/
  * or modify it under the terms of the GNU General Public Li-
@@ -20,7 +20,7 @@
  *
  * Authors:
  *   Lubos Stanek <lubek at users.sourceforge.net>
- *   Florian Forster <octo at verplant.org>
+ *   Florian Forster <octo at collectd.org>
  **/
 /**
  * ignorelist handles plugin's list of configured collectable
@@ -131,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);
@@ -140,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));
@@ -248,6 +250,7 @@ void ignorelist_free (ignorelist_t *il)
                if (this->rmatch != NULL)
                {
                        regfree (this->rmatch);
+                       sfree (this->rmatch);
                        this->rmatch = NULL;
                }
 #endif
@@ -306,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);
-               sstrncpy (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);