]> pilppa.org Git - libplp.git/blobdiff - src/StoreCache.cc
fix potential error from uninitialized variable
[libplp.git] / src / StoreCache.cc
index d95c9fb0fdf72cc74610df68cc1793825f7b7427..fe5c5834be8e64f5b40d7216ba048dfd26a20034 100644 (file)
@@ -7,6 +7,8 @@
 #include <sstream>
 #include <fstream>
 
+#include <unistd.h>
+
 #include "log.h"
 #include "Store.hh"
 #include "StoreCache.hh"
@@ -279,6 +281,8 @@ DataRange *StoreCache::get_sum(EnumSummaryPeriod period_type_param) {
                                        res_data        = NULL;
                                        cnt             = 0;
                                        while(cur_date->before(max_date)) {
+                                               dr      = NULL;
+                                               store   = NULL;
                                                if (period_type_param == PERIOD_YEARLY) {
                                                        store   = new StoreCache(device_id, cur_date);
                                                        dr      = store->get_sum(PERIOD_MONTHLY);
@@ -313,7 +317,8 @@ DataRange *StoreCache::get_sum(EnumSummaryPeriod period_type_param) {
                                                        }
                                                        delete(dr);
                                                }
-                                               delete(store);
+                                               if (store != NULL)
+                                                       delete(store);
                                                if (period_type_param == PERIOD_YEARLY) {
                                                        cur_date->next_month();
                                                }