X-Git-Url: https://git.octo.it/?a=blobdiff_plain;ds=sidebyside;f=src%2Frrd_resize.c;h=9dcfccab95da81afce3aa7a2f421564db69d7535;hb=fd541595aa5d0c19281fda76907847a93f2cfaec;hp=b242b482f5ee5742681c195c1ac005349e83b2ff;hpb=be7a55473565ee9d2bd83f5be70d08dbb9550eb3;p=rrdtool.git diff --git a/src/rrd_resize.c b/src/rrd_resize.c index b242b48..9dcfcca 100644 --- a/src/rrd_resize.c +++ b/src/rrd_resize.c @@ -74,18 +74,22 @@ int rrd_resize( return (-1); } - if (modify < 0) { + if (modify < 0) if ((long) rrdold.rra_def[target_rra].row_cnt <= -modify) { rrd_set_error("This RRA is not that big"); rrd_free(&rrdold); rrd_close(rrd_file); return (-1); } - } else { - /* the size of the new file */ - rrdnew.stat_head = rrd_file->file_len + - (rrdold.stat_head->ds_cnt * sizeof(rrd_value_t) * modify); + /* the size of the new file */ + if ((rrdnew.stat_head = calloc(1, sizeof(stat_head_t))) == NULL) { + rrd_set_error("allocating stat_head for new RRD"); + rrd_free(&rrdold); + rrd_close(rrd_file); + return (-1); } + rrdnew.stat_head->float_cookie = rrd_file->file_len + + (rrdold.stat_head->ds_cnt * sizeof(rrd_value_t) * modify); 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, @@ -162,8 +166,8 @@ int rrd_resize( /* Adding extra rows; insert unknown values just after the ** current row number. */ - l = rrdnew.stat_head->ds_cnt * (rrdnew.rra_ptr[target_rra].cur_row + - 1); + l = rrdnew.stat_head->ds_cnt * + (rrdnew.rra_ptr[target_rra].cur_row + 1); while (l > 0) { rrd_read(rrd_file, &buffer, sizeof(rrd_value_t) * 1); rrd_write(rrd_out_file, &buffer, sizeof(rrd_value_t) * 1); @@ -177,8 +181,8 @@ int rrd_resize( l--; } #else - /* for the mmap case, we did already fill the whole new file with DNAN - * before we copied the old values, so nothing to do here. */ + /* for the mmap case, we did already fill the whole new file with DNAN + * before we copied the old values, so nothing to do here. */ #endif } else { /* Removing rows. Normally this would be just after the cursor @@ -212,7 +216,8 @@ int rrd_resize( } } while (modify < 0) { - rrd_seek(rrd_file, sizeof(rrd_value_t) * rrdnew.stat_head->ds_cnt, + rrd_seek(rrd_file, + sizeof(rrd_value_t) * rrdnew.stat_head->ds_cnt, SEEK_CUR); rrdnew.rra_def[target_rra].row_cnt--; modify++; @@ -243,7 +248,6 @@ int rrd_resize( rrd_free(&rrdold); rrd_close(rrd_file); - rrd_free(&rrdnew); rrd_close(rrd_out_file); return (0);