From: oetiker Date: Mon, 4 Feb 2008 22:34:56 +0000 (+0000) Subject: in rrd_create we do not use mmaping and thus need to free rrd struct members in any... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=3d99d8360586a320cb4e349c0a3c5c2f13b4169c;p=rrdtool.git in rrd_create we do not use mmaping and thus need to free rrd struct members in any case ... git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1278 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/src/rrd_create.c b/src/rrd_create.c index 35a564b..a8f6a29 100644 --- a/src/rrd_create.c +++ b/src/rrd_create.c @@ -121,14 +121,15 @@ int rrd_create_r( /* static header */ if ((rrd.stat_head = calloc(1, sizeof(stat_head_t))) == NULL) { rrd_set_error("allocating rrd.stat_head"); - rrd_free(&rrd); + free(rrd.stat_head); return (-1); } /* live header */ if ((rrd.live_head = calloc(1, sizeof(live_head_t))) == NULL) { rrd_set_error("allocating rrd.live_head"); - rrd_free(&rrd); + free(rrd.stat_head); + free(rrd.live_head); return (-1); } @@ -161,7 +162,8 @@ int rrd_create_r( old_size + sizeof(ds_def_t))) == NULL) { rrd_set_error("allocating rrd.ds_def"); - rrd_free(&rrd); + free(rrd.stat_head); + free(rrd.live_head); return (-1); } memset(&rrd.ds_def[rrd.stat_head->ds_cnt], 0, sizeof(ds_def_t)); @@ -193,7 +195,8 @@ int rrd_create_r( rrd_set_error("invalid DS format"); } if (rrd_test_error()) { - rrd_free(&rrd); + free(rrd.stat_head); + free(rrd.live_head); return -1; } @@ -216,7 +219,8 @@ int rrd_create_r( } if (rrd_test_error()) { - rrd_free(&rrd); + free(rrd.stat_head); + free(rrd.live_head); return -1; } rrd.stat_head->ds_cnt++; @@ -229,7 +233,8 @@ int rrd_create_r( old_size + sizeof(rra_def_t))) == NULL) { rrd_set_error("allocating rrd.rra_def"); - rrd_free(&rrd); + free(rrd.stat_head); + free(rrd.live_head); return (-1); } memset(&rrd.rra_def[rrd.stat_head->rra_cnt], 0, @@ -480,7 +485,8 @@ int rrd_create_r( if (rrd_test_error()) { /* all errors are unrecoverable */ free(argvcopy); - rrd_free(&rrd); + free(rrd.stat_head); + free(rrd.live_head); return (-1); } token = strtok_r(NULL, ":", &tokptr); @@ -507,14 +513,16 @@ int rrd_create_r( if (create_hw_contingent_rras(&rrd, period, hashed_name) == -1) { rrd_set_error("creating contingent RRA"); - rrd_free(&rrd); + free(rrd.stat_head); + free(rrd.live_head); return -1; } } rrd.stat_head->rra_cnt++; } else { rrd_set_error("can't parse argument '%s'", argv[i]); - rrd_free(&rrd); + free(rrd.stat_head); + free(rrd.live_head); return -1; } } @@ -522,13 +530,15 @@ int rrd_create_r( if (rrd.stat_head->rra_cnt < 1) { rrd_set_error("you must define at least one Round Robin Archive"); - rrd_free(&rrd); + free(rrd.stat_head); + free(rrd.live_head); return (-1); } if (rrd.stat_head->ds_cnt < 1) { rrd_set_error("you must define at least one Data Source"); - rrd_free(&rrd); + free(rrd.stat_head); + free(rrd.live_head); return (-1); } return rrd_create_fn(filename, &rrd); @@ -664,7 +674,8 @@ int rrd_create_fn( if ((rrd_file = open(file_name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) { rrd_set_error("creating '%s': %s", file_name, rrd_strerror(errno)); - rrd_free(rrd); + free(rrd->stat_head); + free(rrd->live_head); return (-1); } @@ -679,7 +690,8 @@ int rrd_create_fn( if ((rrd->pdp_prep = calloc(1, sizeof(pdp_prep_t))) == NULL) { rrd_set_error("allocating pdp_prep"); - rrd_free(rrd); + free(rrd->stat_head); + free(rrd->live_head); close(rrd_file); return (-1); } @@ -695,7 +707,8 @@ int rrd_create_fn( if ((rrd->cdp_prep = calloc(1, sizeof(cdp_prep_t))) == NULL) { rrd_set_error("allocating cdp_prep"); - rrd_free(rrd); + free(rrd->stat_head); + free(rrd->live_head); close(rrd_file); return (-1); } @@ -742,7 +755,8 @@ int rrd_create_fn( if ((rrd->rra_ptr = calloc(1, sizeof(rra_ptr_t))) == NULL) { rrd_set_error("allocating rra_ptr"); - rrd_free(rrd); + free(rrd->stat_head); + free(rrd->live_head); close(rrd_file); return (-1); } @@ -759,7 +773,8 @@ int rrd_create_fn( /* write the empty data area */ if ((unknown = (rrd_value_t *) malloc(512 * sizeof(rrd_value_t))) == NULL) { rrd_set_error("allocating unknown"); - rrd_free(rrd); + free(rrd->stat_head); + free(rrd->live_head); close(rrd_file); return (-1); } @@ -777,7 +792,8 @@ int rrd_create_fn( } free(unknown); fdatasync(rrd_file); - rrd_free(rrd); + free(rrd->stat_head); + free(rrd->live_head); if (close(rrd_file) == -1) { rrd_set_error("creating rrd: %s", rrd_strerror(errno)); return -1; @@ -785,6 +801,7 @@ int rrd_create_fn( /* flush all we don't need out of the cache */ rrd_file_dn = rrd_open(file_name, &rrd_dn, RRD_READONLY); rrd_dontneed(rrd_file_dn, &rrd_dn); + rrd_free(&rrd_dn); rrd_close(rrd_file_dn); return (0); }