const char *def,
ds_def_t *ds_def);
-static void rrd_free2(
- rrd_t *rrd); /* our onwn copy, immmune to mmap */
-
int rrd_create(
int argc,
char **argv)
rrd_t rrd;
long i;
unsigned long hashed_name;
-
+ int rc = -1;
+
/* clear any previous errors */
rrd_clear_error();
/* static header */
if ((rrd.stat_head = (stat_head_t*)calloc(1, sizeof(stat_head_t))) == NULL) {
rrd_set_error("allocating rrd.stat_head");
- rrd_free2(&rrd);
- return (-1);
+ goto done;
}
/* live header */
if ((rrd.live_head = (live_head_t*)calloc(1, sizeof(live_head_t))) == NULL) {
rrd_set_error("allocating rrd.live_head");
- rrd_free2(&rrd);
- return (-1);
+ goto done;
}
/* set some defaults */
old_size + sizeof(ds_def_t))) ==
NULL) {
rrd_set_error("allocating rrd.ds_def");
- rrd_free2(&rrd);
- return (-1);
+ goto done;
}
memset(&rrd.ds_def[rrd.stat_head->ds_cnt], 0, sizeof(ds_def_t));
rrd.stat_head->ds_cnt++;
if (rrd_test_error()) {
- rrd_free2(&rrd);
- return -1;
+ goto done;
}
} else if (strncmp(argv[i], "RRA:", 4) == 0) {
old_size + sizeof(rra_def_t))) ==
NULL) {
rrd_set_error("allocating rrd.rra_def");
- rrd_free2(&rrd);
- return (-1);
+ goto done;
}
parseRRA(argv[i], rrd.rra_def + rrd.stat_head->rra_cnt, &rrd,
hashed_name);
if (rrd_test_error()) {
- rrd_free2(&rrd);
- return -1;
+ goto done;
}
rrd.stat_head->rra_cnt++;
rrd.rra_def = handle_dependent_rras(rrd.rra_def, &(rrd.stat_head->rra_cnt),
hashed_name);
if (rrd.rra_def == NULL) {
- rrd_free2(&rrd);
- return -1;
+ goto done;
}
} else {
rrd_set_error("can't parse argument '%s'", argv[i]);
- rrd_free2(&rrd);
- return -1;
+ goto done;
}
}
if (rrd.stat_head->rra_cnt < 1) {
rrd_set_error("you must define at least one Round Robin Archive");
- rrd_free2(&rrd);
- return (-1);
+ goto done;
}
if (rrd.stat_head->ds_cnt < 1) {
rrd_set_error("you must define at least one Data Source");
- rrd_free2(&rrd);
- return (-1);
+ goto done;
}
- return rrd_create_fn(filename, &rrd, no_overwrite);
+ rc = rrd_create_fn(filename, &rrd, no_overwrite);
+
+done:
+ rrd_free(&rrd);
+ return rc;
}
void parseGENERIC_DS(
if ((rrd_file_dn = rrd_open(file_name, rrd, rrd_flags)) == NULL) {
rrd_set_error("creating '%s': %s", file_name, rrd_strerror(errno));
- rrd_free2(rrd);
return (-1);
}
if ((rrd->pdp_prep = (pdp_prep_t*)calloc(1, sizeof(pdp_prep_t))) == NULL) {
rrd_set_error("allocating pdp_prep");
- rrd_free2(rrd);
rrd_close(rrd_file_dn);
return (-1);
}
if ((rrd->cdp_prep = (cdp_prep_t*)calloc(1, sizeof(cdp_prep_t))) == NULL) {
rrd_set_error("allocating cdp_prep");
- rrd_free2(rrd);
rrd_close(rrd_file_dn);
return (-1);
}
if ((rrd->rra_ptr = (rra_ptr_t*)calloc(1, sizeof(rra_ptr_t))) == NULL) {
rrd_set_error("allocating rra_ptr");
- rrd_free2(rrd);
rrd_close(rrd_file_dn);
return (-1);
}
/* write the empty data area */
if ((unknown = (rrd_value_t *) malloc(512 * sizeof(rrd_value_t))) == NULL) {
rrd_set_error("allocating unknown");
- rrd_free2(rrd);
rrd_close(rrd_file_dn);
return (-1);
}
unkn_cnt -= 512;
}
free(unknown);
- rrd_free2(rrd);
if (rrd_close(rrd_file_dn) == -1) {
rrd_set_error("creating rrd: %s", rrd_strerror(errno));
return -1;
if((rrd_file_dn = rrd_open(file_name, &rrd_dn, RRD_READONLY)) != NULL)
{
rrd_dontneed(rrd_file_dn, &rrd_dn);
- /* rrd_free(&rrd_dn); */
+ /* rrd_free(&rrd_dn); */ /* FIXME: Why is this commented out?
+ This would only make sense if
+ we are sure about mmap */
rrd_close(rrd_file_dn);
}
return (0);
}
-static void rrd_free2(
- rrd_t *rrd)
-{
- free(rrd->live_head);
- free(rrd->stat_head);
- free(rrd->ds_def);
- free(rrd->rra_def);
- free(rrd->rra_ptr);
- free(rrd->pdp_prep);
- free(rrd->cdp_prep);
- free(rrd->rrd_value);
-}
-