X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrdtool.c;h=4a3c345ef3ae34f198f8ce89f5b4806e2fe51b95;hb=749b03b3fc459895b7415c7c13753066bf0af55b;hp=764d6d65db0d2b545c94f41b8a105cd0cda3e97e;hpb=7bab45b57d6ef99ae55c499c51478dd63c3b1397;p=collectd.git diff --git a/src/rrdtool.c b/src/rrdtool.c index 764d6d65..4a3c345e 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -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,32 @@ static int rrd_config (const char *key, const char *value) } else if (strcasecmp ("DataDir", key) == 0) { - if (datadir != NULL) - free (datadir); - datadir = strdup (value); - if (datadir != NULL) + char *tmp; + size_t len; + + tmp = strdup (value); + if (tmp == NULL) { - int len = strlen (datadir); - while ((len > 0) && (datadir[len - 1] == '/')) - { - len--; - datadir[len] = '\0'; - } - if (len <= 0) - { - free (datadir); - datadir = NULL; - } + ERROR ("rrdtool plugin: strdup failed."); + return (1); } + + len = strlen (datadir); + while ((len > 0) && (datadir[len - 1] == '/')) + { + len--; + datadir[len] = 0; + } + + if (len == 0) + { + ERROR ("rrdtool plugin: Invalid \"DataDir\" option."); + sfree (tmp); + return (1); + } + + sfree (datadir); + datadir = tmp; } else if (strcasecmp ("StepSize", key) == 0) { @@ -1204,6 +1216,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); }