X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Frrdtool.c;h=6b44f67e48e36757cdd34f4dd8334873fb109aac;hb=d13a04dc3645a21acecc14a4174837766ecb6a2b;hp=764d6d65db0d2b545c94f41b8a105cd0cda3e97e;hpb=06efe4f50bbdfbade922b8a3ee4576eb2cc4562c;p=collectd.git diff --git a/src/rrdtool.c b/src/rrdtool.c index 764d6d65..6b44f67e 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -166,7 +166,7 @@ static int srrd_update (char *filename, char *template, assert (template == NULL); new_argc = 2 + argc; - new_argv = (char **) malloc ((new_argc + 1) * sizeof (char *)); + new_argv = malloc ((new_argc + 1) * sizeof (*new_argv)); if (new_argv == NULL) { ERROR ("rrdtool plugin: malloc failed."); @@ -480,7 +480,7 @@ static int rrd_queue_enqueue (const char *filename, { rrd_queue_t *queue_entry; - queue_entry = (rrd_queue_t *) malloc (sizeof (rrd_queue_t)); + queue_entry = malloc (sizeof (*queue_entry)); if (queue_entry == NULL) return (-1); @@ -733,7 +733,10 @@ static int rrd_cache_insert (const char *filename, { rc = malloc (sizeof (*rc)); if (rc == NULL) + { + pthread_mutex_unlock (&cache_lock); return (-1); + } rc->values_num = 0; rc->values = NULL; rc->first_value = 0; @@ -1005,23 +1008,36 @@ static int rrd_config (const char *key, const char *value) } else if (strcasecmp ("DataDir", key) == 0) { - if (datadir != NULL) - free (datadir); - datadir = strdup (value); + char *tmp; + size_t len; + + tmp = strdup (value); + if (tmp == NULL) + { + ERROR ("rrdtool plugin: strdup failed."); + return (1); + } + + len = strlen (tmp); + while ((len > 0) && (tmp[len - 1] == '/')) + { + len--; + tmp[len] = 0; + } + + if (len == 0) + { + ERROR ("rrdtool plugin: Invalid \"DataDir\" option."); + sfree (tmp); + return (1); + } + if (datadir != NULL) { - int len = strlen (datadir); - while ((len > 0) && (datadir[len - 1] == '/')) - { - len--; - datadir[len] = '\0'; - } - if (len <= 0) - { - free (datadir); - datadir = NULL; - } + sfree (datadir); } + + datadir = tmp; } else if (strcasecmp ("StepSize", key) == 0) { @@ -1204,6 +1220,7 @@ static int rrd_init (void) cache = c_avl_create ((int (*) (const void *, const void *)) strcmp); if (cache == NULL) { + pthread_mutex_unlock (&cache_lock); ERROR ("rrdtool plugin: c_avl_create failed."); return (-1); }