Code

timeseries: Fixed timeseries_destroy().
authorSebastian Harl <sh@tokkee.org>
Thu, 21 Aug 2014 03:15:40 +0000 (20:15 -0700)
committerSebastian Harl <sh@tokkee.org>
Thu, 21 Aug 2014 03:15:40 +0000 (20:15 -0700)
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

index 48da7f8dab9e47a4ad12b77f8df65bf39fc117bc..06c321c3f253198e47b57303bbcbe7b30df4d6ad 100644 (file)
@@ -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 */