From 325795abc4d6530149b5538d3d1136eed3195d16 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Wed, 20 Aug 2014 20:15:40 -0700 Subject: [PATCH] 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. --- src/core/timeseries.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) 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 */ -- 2.30.2