fix indenting ... again
[rrdtool.git] / src / rrd_resize.c
index e29f2dd..52c208b 100644 (file)
@@ -55,22 +55,22 @@ int rrd_resize(
         modify = -modify;
 
 
-    rrd_file = rrd_open(infilename, &rrdold, RRD_READWRITE);
+    rrd_file = rrd_open(infilename, &rrdold, RRD_READWRITE | RRD_COPY);
     if (rrd_file == NULL) {
-        rrd_set_error("could not open RRD");
+        rrd_free(&rrdold);
         return (-1);
     }
     if (LockRRD(rrd_file->fd) != 0) {
         rrd_set_error("could not lock original RRD");
         rrd_free(&rrdold);
-        close(rrd_file->fd);
+        rrd_close(rrd_file);
         return (-1);
     }
 
     if (target_rra >= rrdold.stat_head->rra_cnt) {
         rrd_set_error("no such RRA in this RRD");
         rrd_free(&rrdold);
-        close(rrd_file->fd);
+        rrd_close(rrd_file);
         return (-1);
     }
 
@@ -78,21 +78,22 @@ int rrd_resize(
         if ((long) rrdold.rra_def[target_rra].row_cnt <= -modify) {
             rrd_set_error("This RRA is not that big");
             rrd_free(&rrdold);
-            close(rrd_file->fd);
+            rrd_close(rrd_file);
             return (-1);
         }
 
-    rrd_out_file = rrd_open(outfilename, &rrdnew, RRD_READWRITE|RRD_CREAT);
+    rrd_out_file = rrd_open(outfilename, &rrdnew, RRD_READWRITE | RRD_CREAT);
     if (rrd_out_file == NULL) {
         rrd_set_error("Can't create '%s': %s", outfilename,
                       rrd_strerror(errno));
+        rrd_free(&rrdnew);
         return (-1);
     }
     if (LockRRD(rrd_out_file->fd) != 0) {
         rrd_set_error("could not lock new RRD");
         rrd_free(&rrdold);
-        close(rrd_file->fd);
-        close(rrd_out_file->fd);
+        rrd_close(rrd_file);
+        rrd_close(rrd_out_file);
         return (-1);
     }
 /*XXX: do one write for those parts of header that are unchanged */
@@ -111,16 +112,15 @@ int rrd_resize(
     case 1:
         rrdold.stat_head->version[3] = '3';
         break;
-    default:{
+    default:
         rrd_set_error("Do not know how to handle RRD version %s",
                       rrdold.stat_head->version);
+        rrd_close(rrd_file);
         rrd_free(&rrdold);
-        close(rrd_file->fd);
         return (-1);
-    }
+        break;
     }
 
-
 /* XXX: Error checking? */
     rrd_write(rrd_out_file, rrdnew.stat_head, sizeof(stat_head_t) * 1);
     rrd_write(rrd_out_file, rrdnew.ds_def,
@@ -231,8 +231,11 @@ int rrd_resize(
     rrd_write(rrd_out_file, rrdnew.rra_ptr,
               sizeof(rra_ptr_t) * rrdnew.stat_head->rra_cnt);
 
-    close(rrd_out_file->fd);
     rrd_free(&rrdold);
-    close(rrd_file->fd);
+    rrd_close(rrd_file);
+
+    rrd_free(&rrdnew);
+    rrd_close(rrd_out_file);
+
     return (0);
 }