From: Sebastian Harl Date: Thu, 21 Aug 2014 03:15:40 +0000 (-0700) Subject: timeseries: Fixed timeseries_destroy(). X-Git-Tag: sysdb-0.4.0~22 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=325795abc4d6530149b5538d3d1136eed3195d16;p=sysdb.git timeseries: Fixed timeseries_destroy(). Correctly access all information indexed by data_names_len and make sure not to access array members if the array is NULL. --- diff --git a/src/core/timeseries.c b/src/core/timeseries.c index 48da7f8..06c321c 100644 --- a/src/core/timeseries.c +++ b/src/core/timeseries.c @@ -46,18 +46,25 @@ sdb_timeseries_destroy(sdb_timeseries_t *ts) if (! ts) return; - if (ts->data) + if (ts->data) { + for (i = 0; i < ts->data_names_len; ++i) { + if (ts->data[i]) + free(ts->data[i]); + ts->data[i] = NULL; + } free(ts->data); + } ts->data = NULL; ts->data_len = 0; - for (i = 0; i < ts->data_names_len; ++i) { - if (ts->data_names[i]) - free(ts->data_names[i]); - ts->data_names[i] = NULL; - } - if (ts->data_names) + if (ts->data_names) { + for (i = 0; i < ts->data_names_len; ++i) { + if (ts->data_names[i]) + free(ts->data_names[i]); + ts->data_names[i] = NULL; + } free(ts->data_names); + } ts->data_names = NULL; ts->data_names_len = 0; } /* sdb_timeseries_destroy */