X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Frrdtool.c;h=6b44f67e48e36757cdd34f4dd8334873fb109aac;hb=d13a04dc3645a21acecc14a4174837766ecb6a2b;hp=26d16389c8d2522bd8b6299454aacd780b870434;hpb=8dfaf98cde62e42d4c245400c68ae9c825a2fe68;p=collectd.git diff --git a/src/rrdtool.c b/src/rrdtool.c index 26d16389..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); @@ -1008,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) {