Merge branch 'collectd-5.5'
authorRuben Kerkhof <ruben@rubenkerkhof.com>
Fri, 11 Dec 2015 22:01:06 +0000 (23:01 +0100)
committerRuben Kerkhof <ruben@rubenkerkhof.com>
Fri, 11 Dec 2015 22:01:06 +0000 (23:01 +0100)
1  2 
src/daemon/utils_ignorelist.c

@@@ -89,45 -89,50 +89,45 @@@ static inline void ignorelist_append (i
  }
  
  #if HAVE_REGEX_H
 -static int ignorelist_append_regex(ignorelist_t *il, const char *entry)
 +static int ignorelist_append_regex(ignorelist_t *il, const char *re_str)
  {
        regex_t *re;
 -      ignorelist_item_t *item;
 +      ignorelist_item_t *entry;
        int status;
  
 -      /* create buffer */
        re = malloc (sizeof (*re));
        if (re == NULL)
        {
-               ERROR ("utils_ignorelist: malloc failed");
+               ERROR ("ignorelist_append_regex: malloc failed.");
 -              return ENOMEM;
 +              return (ENOMEM);
        }
        memset (re, 0, sizeof (*re));
  
 -      /* compile regex */
 -      status = regcomp (re, entry, REG_EXTENDED);
 +      status = regcomp (re, re_str, REG_EXTENDED);
        if (status != 0)
        {
-               char errbuf[1024] = "";
-               regerror (status, re, errbuf, sizeof (errbuf));
+               char errbuf[1024];
 -
+               (void) regerror (status, re, errbuf, sizeof (errbuf));
 -              ERROR ("ignorelist_append_regex: Compiling regular expression \"%s\" failed: %s", entry, errbuf);
 +              ERROR ("utils_ignorelist: regcomp failed: %s", errbuf);
-               regfree (re);
++              ERROR ("ignorelist_append_regex: Compiling regular expression \"%s\" failed: %s", re_str, errbuf);
                sfree (re);
 -              return status;
 +              return (status);
        }
  
 -      /* create new entry */
 -      item = malloc (sizeof (*item));
 -      if (item == NULL)
 +      entry = malloc (sizeof (*entry));
 +      if (entry == NULL)
        {
-               ERROR ("utils_ignorelist: malloc failed");
+               ERROR ("ignorelist_append_regex: malloc failed.");
                regfree (re);
                sfree (re);
 -              return ENOMEM;
 +              return (ENOMEM);
        }
 -      memset (item, 0, sizeof (*item));
 -      item->rmatch = re;
 -
 -      /* append new entry */
 -      ignorelist_append (il, item);
 +      memset (entry, 0, sizeof (*entry));
 +      entry->rmatch = re;
  
 +      ignorelist_append (il, entry);
        return (0);
 -} /* int ignorelist_append_regex(ignorelist_t *il, const char *entry) */
 +} /* int ignorelist_append_regex */
  #endif
  
  static int ignorelist_append_string(ignorelist_t *il, const char *entry)
@@@ -195,9 -200,10 +195,10 @@@ ignorelist_t *ignorelist_create (int in
  {
        ignorelist_t *il;
  
-       /* smalloc exits if it failes */
-       il = (ignorelist_t *) smalloc (sizeof (ignorelist_t));
-       memset (il, '\0', sizeof (ignorelist_t));
+       il = malloc (sizeof (*il));
+       if (il == NULL)
+               return NULL;
+       memset (il, 0, sizeof (*il));
  
        /*
         * ->ignore == 0  =>  collect
@@@ -258,11 -264,11 +259,11 @@@ void ignorelist_set_invert (ignorelist_
  
  /*
   * append entry into ignorelist_t
 - * return 1 for success
 + * return 0 for success
   */
  int ignorelist_add (ignorelist_t *il, const char *entry)
  {
-       size_t entry_len;
+       size_t len;
  
        if (il == NULL)
        {
                return (1);
        }
  
-       entry_len = strlen (entry);
+       len = strlen (entry);
  
        /* append nothing */
-       if (entry_len == 0)
+       if (len == 0)
        {
                DEBUG("not appending: empty entry");
                return (1);
  
  #if HAVE_REGEX_H
        /* regex string is enclosed in "/.../" */
-       if ((entry_len > 2) && (entry[0] == '/') && entry[entry_len - 1] == '/')
+       if ((len > 2) && (entry[0] == '/') && entry[len - 1] == '/')
        {
-               char *entry_copy;
-               size_t entry_copy_size;
+               char *copy;
                int status;
  
-               /* We need to copy `entry' since it's const */
-               entry_copy_size = entry_len - 1;
-               entry_copy = smalloc (entry_copy_size);
-               sstrncpy (entry_copy, entry + 1, entry_copy_size);
+               /* skip leading slash */
+               copy = strdup (entry + 1);
+               if (copy == NULL)
+                       return ENOMEM;
+               /* trim trailing slash */
+               copy[strlen (copy) - 1] = 0;
  
-               status = ignorelist_append_regex(il, entry_copy);
-               sfree (entry_copy);
+               status = ignorelist_append_regex (il, copy);
+               sfree (copy);
                return status;
        }
  #endif