Merge branch 'collectd-5.4' into collectd-5.5
authorFlorian Forster <octo@collectd.org>
Fri, 19 Jun 2015 13:11:39 +0000 (15:11 +0200)
committerFlorian Forster <octo@collectd.org>
Fri, 19 Jun 2015 13:11:39 +0000 (15:11 +0200)
19 files changed:
src/apache.c
src/collectdmon.c
src/curl.c
src/curl_json.c
src/curl_xml.c
src/daemon/utils_cache.c
src/gmond.c
src/ipvs.c
src/java.c
src/memcachec.c
src/powerdns.c
src/rrdtool.c
src/snmp.c
src/threshold.c
src/utils_cmd_flush.c
src/utils_cmd_putval.c
src/utils_ignorelist.c
src/utils_latency.c
src/utils_rrdcreate.c

index 0c6318e..8910675 100644 (file)
@@ -81,6 +81,7 @@ static void apache_free (apache_t *st)
                curl_easy_cleanup(st->curl);
                st->curl = NULL;
        }
+       sfree (st);
 } /* apache_free */
 
 static size_t apache_curl_callback (void *buf, size_t size, size_t nmemb,
index 6c50cf1..33f02b4 100644 (file)
@@ -317,7 +317,10 @@ int main (int argc, char **argv)
        openlog ("collectdmon", LOG_CONS | LOG_PID, LOG_DAEMON);
 
        if (-1 == daemonize ())
+       {
+               free (collectd_argv);
                return 1;
+       }
 
        sa.sa_handler = sig_int_term_handler;
        sa.sa_flags   = 0;
@@ -325,11 +328,13 @@ int main (int argc, char **argv)
 
        if (0 != sigaction (SIGINT, &sa, NULL)) {
                syslog (LOG_ERR, "Error: sigaction() failed: %s", strerror (errno));
+               free (collectd_argv);
                return 1;
        }
 
        if (0 != sigaction (SIGTERM, &sa, NULL)) {
                syslog (LOG_ERR, "Error: sigaction() failed: %s", strerror (errno));
+               free (collectd_argv);
                return 1;
        }
 
@@ -337,6 +342,7 @@ int main (int argc, char **argv)
 
        if (0 != sigaction (SIGHUP, &sa, NULL)) {
                syslog (LOG_ERR, "Error: sigaction() failed: %s", strerror (errno));
+               free (collectd_argv);
                return 1;
        }
 
index b750f80..ac4cc51 100644 (file)
@@ -327,7 +327,10 @@ static int cc_config_add_match (web_page_t *page, /* {{{ */
   } /* while (status == 0) */
 
   if (status != 0)
+  {
+    cc_web_match_free (match);
     return (status);
+  }
 
   match->match = match_create_simple (match->regex, match->exclude_regex,
       match->dstype);
index 1c225f7..3ba5560 100644 (file)
@@ -503,6 +503,7 @@ static int cj_config_add_key (cj_t *db, /* {{{ */
   {
     ERROR ("curl_json plugin: cj_config: "
            "Invalid key: %s", ci->key);
+    cj_key_free (key);
     return (-1);
   }
 
@@ -696,6 +697,7 @@ static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */
   {
     ERROR ("curl_json plugin: cj_config: "
            "Invalid key: %s", ci->key);
+    cj_free (db);
     return (-1);
   }
   if (status != 0)
index 689d5e1..37a3686 100644 (file)
@@ -941,6 +941,7 @@ static int cx_config_add_url (oconfig_item_t *ci) /* {{{ */
   {
     ERROR ("curl_xml plugin: cx_config: "
            "Invalid key: %s", ci->key);
+    cx_free (db);
     return (-1);
   }
 
index 46b6631..7b2f958 100644 (file)
@@ -303,7 +303,13 @@ int uc_check_timeout (void)
   pthread_mutex_unlock (&cache_lock);
 
   if (keys_len == 0)
+  {
+    /* realloc() may have been called for these. */
+    sfree (keys);
+    sfree (keys_time);
+    sfree (keys_interval);
     return (0);
+  }
 
   /* Call the "missing" callback for each value. Do this before removing the
    * value from the cache, so that callbacks can still access the data stored,
@@ -647,12 +653,13 @@ int uc_get_names (char ***ret_names, cdtime_t **ret_times, size_t *ret_number)
   if (status != 0)
   {
     size_t i;
-    
+
     for (i = 0; i < number; i++)
     {
       sfree (names[i]);
     }
     sfree (names);
+    sfree (times);
 
     return (-1);
   }
@@ -660,6 +667,8 @@ int uc_get_names (char ***ret_names, cdtime_t **ret_times, size_t *ret_number)
   *ret_names = names;
   if (ret_times != NULL)
     *ret_times = times;
+  else
+    sfree (times);
   *ret_number = number;
 
   return (0);
index 0811c2b..09d7137 100644 (file)
@@ -222,13 +222,13 @@ static int create_sockets (socket_entry_t **ret_sockets, /* {{{ */
   struct addrinfo *ai_ptr;
   int              ai_return;
 
-  socket_entry_t *sockets;
-  size_t          sockets_num;
+  socket_entry_t *sockets = NULL;
+  size_t          sockets_num = 0;
 
   int status;
-    
-  sockets     = *ret_sockets;
-  sockets_num = *ret_sockets_num;
+
+  if (*ret_sockets != NULL)
+    return (EINVAL);
 
   memset (&ai_hints, 0, sizeof (ai_hints));
   ai_hints.ai_flags    = 0;
@@ -360,8 +360,11 @@ static int create_sockets (socket_entry_t **ret_sockets, /* {{{ */
 
   freeaddrinfo (ai_list);
 
-  if ((*ret_sockets_num) >= sockets_num)
+  if (sockets_num == 0)
+  {
+    sfree (sockets);
     return (-1);
+  }
 
   *ret_sockets = sockets;
   *ret_sockets_num = sockets_num;
index fa89489..cbb5542 100644 (file)
@@ -295,7 +295,10 @@ static void cipvs_submit_service (struct ip_vs_service_entry *se)
        int i = 0;
 
        if (0 != get_pi (se, pi, sizeof (pi)))
+       {
+               free (dests);
                return;
+       }
 
        cipvs_submit_connections (pi, NULL, stats.conns);
        cipvs_submit_if (pi, "if_packets", NULL, stats.inpkts, stats.outpkts);
index 2f1efbf..c74fe6c 100644 (file)
@@ -1817,6 +1817,7 @@ static cjni_callback_info_t *cjni_callback_info_create (JNIEnv *jvm_env, /* {{{
     pthread_mutex_unlock (&java_callbacks_lock);
     ERROR ("java plugin: cjni_callback_info_create: strdup failed.");
     (*jvm_env)->ReleaseStringUTFChars (jvm_env, o_name, c_name);
+    sfree (cbi);
     return (NULL);
   }
 
@@ -1826,7 +1827,8 @@ static cjni_callback_info_t *cjni_callback_info_create (JNIEnv *jvm_env, /* {{{
   if (cbi->object == NULL)
   {
     ERROR ("java plugin: cjni_callback_info_create: NewGlobalRef failed.");
-    free (cbi);
+    sfree (cbi->name);
+    sfree (cbi);
     return (NULL);
   }
 
@@ -1834,7 +1836,9 @@ static cjni_callback_info_t *cjni_callback_info_create (JNIEnv *jvm_env, /* {{{
   if (cbi->class == NULL)
   {
     ERROR ("java plugin: cjni_callback_info_create: GetObjectClass failed.");
-    free (cbi);
+    (*jvm_env)->DeleteGlobalRef (jvm_env, cbi->object);
+    sfree (cbi->name);
+    sfree (cbi);
     return (NULL);
   }
 
@@ -1845,7 +1849,9 @@ static cjni_callback_info_t *cjni_callback_info_create (JNIEnv *jvm_env, /* {{{
     ERROR ("java plugin: cjni_callback_info_create: "
         "Cannot find the `%s' method with signature `%s'.",
         method_name, method_signature);
-    free (cbi);
+    (*jvm_env)->DeleteGlobalRef (jvm_env, cbi->object);
+    sfree (cbi->name);
+    sfree (cbi);
     return (NULL);
   }
 
index 37f1894..013b6c4 100644 (file)
@@ -263,7 +263,10 @@ static int cmc_config_add_match (web_page_t *page, /* {{{ */
   } /* while (status == 0) */
 
   if (status != 0)
+  {
+    cmc_web_match_free (match);
     return (status);
+  }
 
   match->match = match_create_simple (match->regex, match->exclude_regex,
       match->dstype);
index 99b4df6..f9f291a 100644 (file)
@@ -737,25 +737,6 @@ static int powerdns_read_recursor (list_item_t *item) /* {{{ */
   return (0);
 } /* }}} int powerdns_read_recursor */
 
-static int powerdns_config_add_string (const char *name, /* {{{ */
-    char **dest,
-    oconfig_item_t *ci)
-{
-  if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
-  {
-    WARNING ("powerdns plugin: `%s' needs exactly one string argument.",
-       name);
-    return (-1);
-  }
-
-  sfree (*dest);
-  *dest = strdup (ci->values[0].value.string);
-  if (*dest == NULL)
-    return (-1);
-
-  return (0);
-} /* }}} int powerdns_config_add_string */
-
 static int powerdns_config_add_collect (list_item_t *li, /* {{{ */
     oconfig_item_t *ci)
 {
@@ -866,7 +847,7 @@ static int powerdns_config_add_server (oconfig_item_t *ci) /* {{{ */
     if (strcasecmp ("Collect", option->key) == 0)
       status = powerdns_config_add_collect (item, option);
     else if (strcasecmp ("Socket", option->key) == 0)
-      status = powerdns_config_add_string ("Socket", &socket_temp, option);
+      status = cf_util_get_string (option, &socket_temp);
     else
     {
       ERROR ("powerdns plugin: Option `%s' not allowed here.", option->key);
@@ -906,12 +887,14 @@ static int powerdns_config_add_server (oconfig_item_t *ci) /* {{{ */
 
   if (status != 0)
   {
+    sfree (socket_temp);
     sfree (item);
     return (-1);
   }
 
   DEBUG ("powerdns plugin: Add server: instance = %s;", item->instance);
 
+  sfree (socket_temp);
   return (0);
 } /* }}} int powerdns_config_add_server */
 
index bebf468..8497a24 100644 (file)
@@ -743,6 +743,7 @@ static int rrd_cache_insert (const char *filename,
                new_rc = 1;
        }
 
+       assert (value_time > 0); /* plugin_dispatch() ensures this. */
        if (rc->last_value >= value_time)
        {
                pthread_mutex_unlock (&cache_lock);
index 260eff1..8564c68 100644 (file)
@@ -1235,16 +1235,17 @@ static int csnmp_dispatch_table (host_definition_t *host, data_definition_t *dat
     return (-1);
   }
   assert (ds->ds_num == data->values_len);
+  assert (data->values_len > 0);
 
   instance_list_ptr = instance_list;
 
-  value_table_ptr = malloc (sizeof (*value_table_ptr) * data->values_len);
+  value_table_ptr = calloc ((size_t) data->values_len, sizeof (*value_table_ptr));
   if (value_table_ptr == NULL)
     return (-1);
   for (i = 0; i < data->values_len; i++)
     value_table_ptr[i] = value_table[i];
 
-  vl.values_len = ds->ds_num;
+  vl.values_len = data->values_len;
   vl.values = malloc (sizeof (*vl.values) * vl.values_len);
   if (vl.values == NULL)
   {
index a8900db..8dcb711 100644 (file)
@@ -512,10 +512,9 @@ static int ut_report_state (const data_set_t *ds,
   if (state == STATE_OKAY)
   {
     if (state_old == STATE_MISSING)
-      status = ssnprintf (buf, bufsize,
-          ": Value is no longer missing.");
+      ssnprintf (buf, bufsize, ": Value is no longer missing.");
     else
-      status = ssnprintf (buf, bufsize,
+      ssnprintf (buf, bufsize,
           ": All data sources are within range again. "
           "Current value of \"%s\" is %f.",
           ds->ds[ds_index].name, values[ds_index]);
@@ -532,7 +531,7 @@ static int ut_report_state (const data_set_t *ds,
     {
       if (!isnan (min) && !isnan (max))
       {
-        status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
+        ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
             "%f. That is within the %s region of %f%s and %f%s.",
             ds->ds[ds_index].name, values[ds_index],
             (state == STATE_ERROR) ? "failure" : "warning",
@@ -541,13 +540,13 @@ static int ut_report_state (const data_set_t *ds,
       }
       else
       {
-       status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
-           "%f. That is %s the %s threshold of %f%s.",
-           ds->ds[ds_index].name, values[ds_index],
-           isnan (min) ? "below" : "above",
-           (state == STATE_ERROR) ? "failure" : "warning",
-           isnan (min) ? max : min,
-           ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "");
+        ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
+            "%f. That is %s the %s threshold of %f%s.",
+            ds->ds[ds_index].name, values[ds_index],
+            isnan (min) ? "below" : "above",
+            (state == STATE_ERROR) ? "failure" : "warning",
+            isnan (min) ? max : min,
+            ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "");
       }
     }
     else if (th->flags & UT_FLAG_PERCENTAGE)
@@ -570,7 +569,7 @@ static int ut_report_state (const data_set_t *ds,
       else
         value = 100.0 * values[ds_index] / sum;
 
-      status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
+      ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
           "%g (%.2f%%). That is %s the %s threshold of %.2f%%.",
           ds->ds[ds_index].name, values[ds_index], value,
           (value < min) ? "below" : "above",
@@ -579,12 +578,12 @@ static int ut_report_state (const data_set_t *ds,
     }
     else /* is not inverted */
     {
-      status = ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
-         "%f. That is %s the %s threshold of %f.",
-         ds->ds[ds_index].name, values[ds_index],
-         (values[ds_index] < min) ? "below" : "above",
-         (state == STATE_ERROR) ? "failure" : "warning",
-         (values[ds_index] < min) ? min : max);
+      ssnprintf (buf, bufsize, ": Data source \"%s\" is currently "
+          "%f. That is %s the %s threshold of %f.",
+          ds->ds[ds_index].name, values[ds_index],
+          (values[ds_index] < min) ? "below" : "above",
+          (state == STATE_ERROR) ? "failure" : "warning",
+          (values[ds_index] < min) ? min : max);
     }
   }
 
index 089ab70..f19835e 100644 (file)
 #include "plugin.h"
 #include "utils_parse_option.h"
 
-#define print_to_socket(fh, ...) \
-       do { \
-               if (fprintf (fh, __VA_ARGS__) < 0) { \
-                       char errbuf[1024]; \
-                       WARNING ("handle_flush: failed to write to socket #%i: %s", \
-                                       fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \
-                       return -1; \
-               } \
-               fflush(fh); \
-       } while (0)
-
-static int add_to_array (char ***array, int *array_num, char *value)
-{
-       char **temp;
-
-       temp = (char **) realloc (*array, sizeof (char *) * (*array_num + 1));
-       if (temp == NULL)
-               return (-1);
-
-       *array = temp;
-       (*array)[*array_num] = value;
-       (*array_num)++;
-
-       return (0);
-} /* int add_to_array */
-
 int handle_flush (FILE *fh, char *buffer)
 {
        int success = 0;
@@ -64,11 +38,24 @@ int handle_flush (FILE *fh, char *buffer)
 
        double timeout = 0.0;
        char **plugins = NULL;
-       int plugins_num = 0;
+       size_t plugins_num = 0;
        char **identifiers = NULL;
-       int identifiers_num = 0;
+       size_t identifiers_num = 0;
 
-       int i;
+       size_t i;
+
+#define PRINT_TO_SOCK(fh, ...) \
+       do { \
+               if (fprintf (fh, __VA_ARGS__) < 0) { \
+                       char errbuf[1024]; \
+                       WARNING ("handle_flush: failed to write to socket #%i: %s", \
+                                       fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \
+                       strarray_free (plugins, plugins_num); \
+                       strarray_free (identifiers, identifiers_num); \
+                       return -1; \
+               } \
+               fflush(fh); \
+       } while (0)
 
        if ((fh == NULL) || (buffer == NULL))
                return (-1);
@@ -78,7 +65,7 @@ int handle_flush (FILE *fh, char *buffer)
 
        if (strncasecmp ("FLUSH", buffer, strlen ("FLUSH")) != 0)
        {
-               print_to_socket (fh, "-1 Cannot parse command.\n");
+               PRINT_TO_SOCK (fh, "-1 Cannot parse command.\n");
                return (-1);
        }
        buffer += strlen ("FLUSH");
@@ -94,34 +81,30 @@ int handle_flush (FILE *fh, char *buffer)
                status = parse_option (&buffer, &opt_key, &opt_value);
                if (status != 0)
                {
-                       print_to_socket (fh, "-1 Parsing options failed.\n");
-                       sfree (plugins);
-                       sfree (identifiers);
+                       PRINT_TO_SOCK (fh, "-1 Parsing options failed.\n");
+                       strarray_free (plugins, plugins_num);
+                       strarray_free (identifiers, identifiers_num);
                        return (-1);
                }
 
                if (strcasecmp ("plugin", opt_key) == 0)
-               {
-                       add_to_array (&plugins, &plugins_num, opt_value);
-               }
+                       strarray_add (&plugins, &plugins_num, opt_value);
                else if (strcasecmp ("identifier", opt_key) == 0)
-               {
-                       add_to_array (&identifiers, &identifiers_num, opt_value);
-               }
+                       strarray_add (&identifiers, &identifiers_num, opt_value);
                else if (strcasecmp ("timeout", opt_key) == 0)
                {
                        char *endptr;
-                       
+
                        errno = 0;
                        endptr = NULL;
                        timeout = strtod (opt_value, &endptr);
 
                        if ((endptr == opt_value) || (errno != 0) || (!isfinite (timeout)))
                        {
-                               print_to_socket (fh, "-1 Invalid value for option `timeout': "
+                               PRINT_TO_SOCK (fh, "-1 Invalid value for option `timeout': "
                                                "%s\n", opt_value);
-                               sfree (plugins);
-                               sfree (identifiers);
+                               strarray_free (plugins, plugins_num);
+                               strarray_free (identifiers, identifiers_num);
                                return (-1);
                        }
                        else if (timeout < 0.0)
@@ -131,34 +114,29 @@ int handle_flush (FILE *fh, char *buffer)
                }
                else
                {
-                       print_to_socket (fh, "-1 Cannot parse option %s\n", opt_key);
-                       sfree (plugins);
-                       sfree (identifiers);
+                       PRINT_TO_SOCK (fh, "-1 Cannot parse option %s\n", opt_key);
+                       strarray_free (plugins, plugins_num);
+                       strarray_free (identifiers, identifiers_num);
                        return (-1);
                }
        } /* while (*buffer != 0) */
 
-       /* Add NULL entries for `any plugin' and/or `any value' if nothing was
-        * specified. */
-       if (plugins_num == 0)
-               add_to_array (&plugins, &plugins_num, NULL);
-
-       if (identifiers_num == 0)
-               add_to_array (&identifiers, &identifiers_num, NULL);
-
-       for (i = 0; i < plugins_num; i++)
+       for (i = 0; (i == 0) || (i < plugins_num); i++)
        {
-               char *plugin;
+               char *plugin = NULL;
                int j;
 
-               plugin = plugins[i];
+               if (plugins_num != 0)
+                       plugin = plugins[i];
 
-               for (j = 0; j < identifiers_num; j++)
+               for (j = 0; (j == 0) || (j < identifiers_num); j++)
                {
-                       char *identifier;
+                       char *identifier = NULL;
                        int status;
 
-                       identifier = identifiers[j];
+                       if (identifiers_num != 0)
+                               identifier = identifiers[j];
+
                        status = plugin_flush (plugin,
                                        DOUBLE_TO_CDTIME_T (timeout),
                                        identifier);
@@ -169,20 +147,13 @@ int handle_flush (FILE *fh, char *buffer)
                }
        }
 
-       if ((success + error) > 0)
-       {
-               print_to_socket (fh, "0 Done: %i successful, %i errors\n",
-                               success, error);
-       }
-       else
-       {
-               plugin_flush (NULL, DOUBLE_TO_CDTIME_T (timeout), NULL);
-               print_to_socket (fh, "0 Done\n");
-       }
+       PRINT_TO_SOCK (fh, "0 Done: %i successful, %i errors\n",
+                       success, error);
 
-       sfree (plugins);
-       sfree (identifiers);
+       strarray_free (plugins, plugins_num);
+       strarray_free (identifiers, identifiers_num);
        return (0);
+#undef PRINT_TO_SOCK
 } /* int handle_flush */
 
 /* vim: set sw=4 ts=4 tw=78 noexpandtab : */
index c717f0b..7b0258c 100644 (file)
             char errbuf[1024]; \
             WARNING ("handle_putval: failed to write to socket #%i: %s", \
                     fileno (fh), sstrerror (errno, errbuf, sizeof (errbuf))); \
+            sfree (vl.values); \
             return -1; \
         } \
         fflush(fh); \
     } while (0)
 
-static int dispatch_values (const data_set_t *ds, value_list_t *vl,
-               FILE *fh, char *buffer)
-{
-       int status;
-
-       status = parse_values (buffer, vl, ds);
-       if (status != 0)
-       {
-               print_to_socket (fh, "-1 Parsing the values string failed.\n");
-               return (-1);
-       }
-
-       plugin_dispatch_values (vl);
-       return (0);
-} /* int dispatch_values */
-
 static int set_option (value_list_t *vl, const char *key, const char *value)
 {
        if ((vl == NULL) || (key == NULL) || (value == NULL))
@@ -97,6 +82,7 @@ int handle_putval (FILE *fh, char *buffer)
 
        const data_set_t *ds;
        value_list_t vl = VALUE_LIST_INIT;
+       vl.values = NULL;
 
        DEBUG ("utils_cmd_putval: handle_putval (fh = %p, buffer = %s);",
                        (void *) fh, buffer);
@@ -196,6 +182,7 @@ int handle_putval (FILE *fh, char *buffer)
                        /* parse_option failed, buffer has been modified.
                         * => we need to abort */
                        print_to_socket (fh, "-1 Misformatted option.\n");
+                       sfree (vl.values);
                        return (-1);
                }
                else if (status == 0)
@@ -212,16 +199,20 @@ int handle_putval (FILE *fh, char *buffer)
                if (status != 0)
                {
                        print_to_socket (fh, "-1 Misformatted value.\n");
+                       sfree (vl.values);
                        return (-1);
                }
                assert (string != NULL);
 
-               status = dispatch_values (ds, &vl, fh, string);
+               status = parse_values (string, &vl, ds);
                if (status != 0)
                {
-                       /* An error has already been printed. */
+                       print_to_socket (fh, "-1 Parsing the values string failed.\n");
+                       sfree (vl.values);
                        return (-1);
                }
+
+               plugin_dispatch_values (&vl);
                values_submitted++;
        } /* while (*buffer != 0) */
        /* Done parsing the options. */
@@ -230,8 +221,7 @@ int handle_putval (FILE *fh, char *buffer)
                        values_submitted,
                        (values_submitted == 1) ? "value has" : "values have");
 
-       sfree (vl.values); 
-
+       sfree (vl.values);
        return (0);
 } /* int handle_putval */
 
index 0ad252b..7b1c7d2 100644 (file)
@@ -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
index 7f60e11..c6a1ff6 100644 (file)
@@ -117,6 +117,7 @@ latency_counter_t *latency_counter_create () /* {{{ */
   lc = malloc (sizeof (*lc));
   if (lc == NULL)
     return (NULL);
+  memset (lc, 0, sizeof (*lc));
 
   latency_counter_reset (lc);
   lc->bin_width = HISTOGRAM_DEFAULT_BIN_WIDTH;
index 220446a..5add323 100644 (file)
@@ -171,14 +171,10 @@ static int rra_get (char ***ret, const value_list_t *vl, /* {{{ */
 
   int rra_max;
 
-  int span;
-
   int cdp_num;
   int cdp_len;
   int i, j;
 
-  char buffer[128];
-
   /* The stepsize we use here: If it is user-set, use it. If not, use the
    * interval of the value-list. */
   int ss;
@@ -218,16 +214,17 @@ static int rra_get (char ***ret, const value_list_t *vl, /* {{{ */
   }
 
   rra_max = rts_num * rra_types_num;
+  assert (rra_max > 0);
 
-  if ((rra_def = (char **) malloc ((rra_max + 1) * sizeof (char *))) == NULL)
+  if ((rra_def = malloc ((rra_max + 1) * sizeof (*rra_def))) == NULL)
     return (-1);
-  memset (rra_def, '\0', (rra_max + 1) * sizeof (char *));
+  memset (rra_def, 0, (rra_max + 1) * sizeof (*rra_def));
   rra_num = 0;
 
   cdp_len = 0;
   for (i = 0; i < rts_num; i++)
   {
-    span = rts[i];
+    int span = rts[i];
 
     if ((span / ss) < cfg->rrarows)
       span = ss * cfg->rrarows;
@@ -243,6 +240,7 @@ static int rra_get (char ***ret, const value_list_t *vl, /* {{{ */
 
     for (j = 0; j < rra_types_num; j++)
     {
+      char buffer[128];
       int status;
 
       if (rra_num >= rra_max)
@@ -261,6 +259,12 @@ static int rra_get (char ***ret, const value_list_t *vl, /* {{{ */
     }
   }
 
+  if (rra_num <= 0)
+  {
+    sfree (rra_def);
+    return (0);
+  }
+
   *ret = rra_def;
   return (rra_num);
 } /* }}} int rra_get */
@@ -286,7 +290,9 @@ static int ds_get (char ***ret, /* {{{ */
   char max[32];
   char buffer[128];
 
-  ds_def = (char **) malloc (ds->ds_num * sizeof (char *));
+  assert (ds->ds_num > 0);
+
+  ds_def = malloc (ds->ds_num * sizeof (*ds_def));
   if (ds_def == NULL)
   {
     char errbuf[1024];
@@ -294,7 +300,7 @@ static int ds_get (char ***ret, /* {{{ */
         sstrerror (errno, errbuf, sizeof (errbuf)));
     return (-1);
   }
-  memset (ds_def, '\0', ds->ds_num * sizeof (char *));
+  memset (ds_def, 0, ds->ds_num * sizeof (*ds_def));
 
   for (ds_num = 0; ds_num < ds->ds_num; ds_num++)
   {
@@ -352,6 +358,12 @@ static int ds_get (char ***ret, /* {{{ */
     return (-1);
   }
 
+  if (ds_num <= 0)
+  {
+    sfree (ds_def);
+    return (0);
+  }
+
   *ret = ds_def;
   return (ds_num);
 } /* }}} int ds_get */
@@ -651,9 +663,9 @@ int cu_rrd_create_file (const char *filename, /* {{{ */
 {
   char **argv;
   int argc;
-  char **rra_def;
+  char **rra_def = NULL;
   int rra_num;
-  char **ds_def;
+  char **ds_def = NULL;
   int ds_num;
   int status = 0;
   time_t last_up;
@@ -671,6 +683,7 @@ int cu_rrd_create_file (const char *filename, /* {{{ */
   if ((ds_num = ds_get (&ds_def, ds, vl, cfg)) < 1)
   {
     ERROR ("cu_rrd_create_file failed: Could not calculate DSes");
+    rra_free (rra_num, rra_def);
     return (-1);
   }
 
@@ -681,6 +694,8 @@ int cu_rrd_create_file (const char *filename, /* {{{ */
     char errbuf[1024];
     ERROR ("cu_rrd_create_file failed: %s",
         sstrerror (errno, errbuf, sizeof (errbuf)));
+    rra_free (rra_num, rra_def);
+    ds_free (ds_num, ds_def);
     return (-1);
   }