Code

make sure rrdold members are not pointing anywhere after asigning them to rrdnew...
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Thu, 22 Oct 2009 07:07:23 +0000 (07:07 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Thu, 22 Oct 2009 07:07:23 +0000 (07:07 +0000)
git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.3@1941 a5681a0c-68f1-0310-ab6d-d61299d08faa

program/src/rrd_resize.c

index 771209f438f37d679b65a97e3e7db234bcb31a63..2049982aa46bd1b0d1fb2d4aa3db3b46bd59c55e 100644 (file)
@@ -143,62 +143,19 @@ int rrd_resize(
         return (-1);
     }
      
-#ifndef WIN32
     memcpy(rrdnew.stat_head,rrdold.stat_head,sizeof(stat_head_t));
     rrdnew.ds_def = rrdold.ds_def;
-    memcpy(rrdnew.rra_def,rrdold.rra_def,sizeof(rra_def_t) * rrdold.stat_head->rra_cnt);    
+
+    /* we are going to free rrdold later on, so make sure its not still pointing to the new stuff */
+    rrdold.live_head = NULL;
+    memcpy(rrdnew.rra_def,rrdold.rra_def,sizeof(rra_def_t) * rrdold.stat_head->rra_cnt);      
     rrdnew.live_head = rrdold.live_head;
+    rrdold.live_head = NULL;
     rrdnew.pdp_prep = rrdold.pdp_prep;
+    rrdold.pdp_prep = NULL;
     rrdnew.cdp_prep = rrdold.cdp_prep;
+    rrdold.cdp_prep = NULL;
     memcpy(rrdnew.rra_ptr,rrdold.rra_ptr,sizeof(rra_ptr_t) * rrdold.stat_head->rra_cnt);
-#else // WIN32
-       /*
-        * For windows Other fields also should be allocated. Crashes otherwise
-        */
-
-    if ((rrdnew.ds_def = (ds_def_t*)malloc(sizeof(ds_def_t) * rrdold.stat_head->ds_cnt)) == NULL) {
-        rrd_set_error("allocating ds_def for new RRD");
-        rrd_free(&rrdnew);
-        rrd_free(&rrdold);
-        rrd_close(rrd_file);
-        rrd_close(rrd_out_file);
-        return (-1);
-    }
-
-    if ((rrdnew.live_head = (live_head_t*)malloc(sizeof(live_head_t))) == NULL) {
-        rrd_set_error("allocating live_head for new RRD");
-        rrd_free(&rrdnew);
-        rrd_free(&rrdold);
-        rrd_close(rrd_file);
-        rrd_close(rrd_out_file);
-        return (-1);
-    }
-
-    if ((rrdnew.pdp_prep = (pdp_prep_t*)malloc(sizeof(pdp_prep_t))) == NULL) {
-        rrd_set_error("allocating pdp_prep for new RRD");
-        rrd_free(&rrdnew);
-        rrd_free(&rrdold);
-        rrd_close(rrd_file);
-        rrd_close(rrd_out_file);
-        return (-1);
-    }
-
-    if ((rrdnew.cdp_prep = (cdp_prep_t*)malloc(sizeof(cdp_prep_t))) == NULL) {
-        rrd_set_error("allocating cdp_prep for new RRD");
-        rrd_free(&rrdnew);
-        rrd_free(&rrdold);
-        rrd_close(rrd_file);
-        rrd_close(rrd_out_file);
-        return (-1);
-    }
-    memcpy(rrdnew.stat_head,rrdold.stat_head,sizeof(stat_head_t));
-    memcpy(rrdnew.ds_def,rrdold.ds_def,sizeof(ds_def_t) * rrdold.stat_head->ds_cnt);
-    memcpy(rrdnew.rra_def,rrdold.rra_def,sizeof(rra_def_t) * rrdold.stat_head->rra_cnt);    
-    memcpy(rrdnew.live_head,rrdold.live_head,sizeof(live_head_t));
-    memcpy(rrdnew.pdp_prep,rrdold.pdp_prep,sizeof(pdp_prep_t));
-    memcpy(rrdnew.cdp_prep,rrdold.cdp_prep,sizeof(cdp_prep_t));
-    memcpy(rrdnew.rra_ptr,rrdold.rra_ptr,sizeof(rra_ptr_t) * rrdold.stat_head->rra_cnt);
-#endif // WIN32
 
     version = atoi(rrdold.stat_head->version);
     switch (version) {