summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1bf4194)
raw | patch | inline | side by side (parent: 1bf4194)
author | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Wed, 30 May 2007 12:39:30 +0000 (12:39 +0000) | ||
committer | oetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa> | |
Wed, 30 May 2007 12:39:30 +0000 (12:39 +0000) |
- rrd_close(): call close on the file and use rrd_close consistently
- clean up some error paths. The fadvise error path is leaking memory (see XXX in these spots).
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1092 a5681a0c-68f1-0310-ab6d-d61299d08faa
- clean up some error paths. The fadvise error path is leaking memory (see XXX in these spots).
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@1092 a5681a0c-68f1-0310-ab6d-d61299d08faa
src/rrd_create.c | patch | blob | history | |
src/rrd_dump.c | patch | blob | history | |
src/rrd_fetch.c | patch | blob | history | |
src/rrd_first.c | patch | blob | history | |
src/rrd_info.c | patch | blob | history | |
src/rrd_last.c | patch | blob | history | |
src/rrd_lastupdate.c | patch | blob | history | |
src/rrd_open.c | patch | blob | history | |
src/rrd_resize.c | patch | blob | history | |
src/rrd_tune.c | patch | blob | history | |
src/rrd_update.c | patch | blob | history |
diff --git a/src/rrd_create.c b/src/rrd_create.c
index d36cf3cfa8751a2435cd0958fd6be5b6abdb0fcd..35a06b1d10165899ff7c505b5cc7248785b378bb 100644 (file)
--- a/src/rrd_create.c
+++ b/src/rrd_create.c
}
}
if (optind == argc) {
- rrd_set_error("what is the name of the rrd file you want to create?");
+ rrd_set_error("need name of an rrd file to create");
return -1;
}
rc = rrd_create_r(argv[optind],
diff --git a/src/rrd_dump.c b/src/rrd_dump.c
index 0b9310334734374989caef73d4a52995d0250bb3..316814d349c7f62f4832594815375e7e6e2ebecd 100644 (file)
--- a/src/rrd_dump.c
+++ b/src/rrd_dump.c
}
fprintf(out_file, "</rrd>\n");
rrd_free(&rrd);
- close(rrd_file->fd);
if (out_file != stdout) {
fclose(out_file);
}
- return (0);
+ return rrd_close(rrd_file);
}
diff --git a/src/rrd_fetch.c b/src/rrd_fetch.c
index 87c3cd6789b66b6f10b87e645a7bebfb9910627e..618f3d3036a4561eda0c833ac3cbee89c02b5f3e 100644 (file)
--- a/src/rrd_fetch.c
+++ b/src/rrd_fetch.c
cf = argv[optind + 1];
if (rrd_fetch_r(argv[optind], cf, start, end, step, ds_cnt, ds_namv, data)
- == -1)
+ != 0)
return (-1);
return (0);
}
rrd_file = rrd_open(filename, &rrd, RRD_READONLY);
if (rrd_file == NULL)
- return (-1);
+ goto err_free;
/* when was the really last update of this file ? */
if (((*ds_namv) =
(char **) malloc(rrd.stat_head->ds_cnt * sizeof(char *))) == NULL) {
rrd_set_error("malloc fetch ds_namv array");
- rrd_free(&rrd);
- close(rrd_file->fd);
- return (-1);
+ goto err_close;
}
for (i = 0; (unsigned long) i < rrd.stat_head->ds_cnt; i++) {
if ((((*ds_namv)[i]) = malloc(sizeof(char) * DS_NAM_SIZE)) == NULL) {
rrd_set_error("malloc fetch ds_namv entry");
- rrd_free(&rrd);
- free(*ds_namv);
- close(rrd_file->fd);
- return (-1);
+ goto err_free_ds_namv;
}
strncpy((*ds_namv)[i], rrd.ds_def[i].ds_nam, DS_NAM_SIZE - 1);
(*ds_namv)[i][DS_NAM_SIZE - 1] = '\0';
best_full_rra = i;
#ifdef DEBUG
fprintf(stderr, "best full match so far\n");
-#endif
} else {
-#ifdef DEBUG
fprintf(stderr, "full match, not best\n");
#endif
}
else {
rrd_set_error
("the RRD does not contain an RRA matching the chosen CF");
- rrd_free(&rrd);
- close(rrd_file->fd);
- return (-1);
+ goto err_free_all_ds_namv;
}
/* set the wish parameters to their real values */
*ds_cnt = rrd.stat_head->ds_cnt;
if (((*data) = malloc(*ds_cnt * rows * sizeof(rrd_value_t))) == NULL) {
rrd_set_error("malloc fetch data area");
- for (i = 0; (unsigned long) i < *ds_cnt; i++)
- free((*ds_namv)[i]);
- free(*ds_namv);
- rrd_free(&rrd);
- close(rrd_file->fd);
- return (-1);
+ goto err_free_all_ds_namv;
}
data_ptr = (*data);
* sizeof(rrd_value_t))),
SEEK_SET) != 0) {
rrd_set_error("seek error in RRA");
- for (i = 0; (unsigned) i < *ds_cnt; i++)
- free((*ds_namv)[i]);
- free(*ds_namv);
- rrd_free(&rrd);
- free(*data);
- *data = NULL;
- close(rrd_file->fd);
- return (-1);
-
+ goto err_free_data;
}
#ifdef DEBUG
fprintf(stderr, "First Seek: rra_base %lu rra_pointer %lu\n",
* sizeof(rrd_value_t)),
SEEK_SET) != 0) {
rrd_set_error("wrap seek in RRA did fail");
- for (ii = 0; (unsigned) ii < *ds_cnt; ii++)
- free((*ds_namv)[ii]);
- free(*ds_namv);
- rrd_free(&rrd);
- free(*data);
- *data = NULL;
- close(rrd_file->fd);
- return (-1);
+ goto err_free_data;
}
#ifdef DEBUG
fprintf(stderr, "wrap seek ...\n");
if (rrd_read(rrd_file, data_ptr, sizeof(rrd_value_t) * (*ds_cnt))
!= (ssize_t) (sizeof(rrd_value_t) * (*ds_cnt))) {
rrd_set_error("fetching cdp from rra");
- for (ii = 0; (unsigned) ii < *ds_cnt; ii++)
- free((*ds_namv)[ii]);
- free(*ds_namv);
- rrd_free(&rrd);
- free(*data);
- *data = NULL;
- close(rrd_file->fd);
- return (-1);
+ goto err_free_data;
}
#ifdef HAVE_POSIX_FADVISE
/* don't pollute the buffer cache with data read from the file. We do this while reading to
POSIX_FADV_DONTNEED)) {
rrd_set_error("setting POSIX_FADV_DONTNEED on '%s': %s",
filename, rrd_strerror(errno));
- close(rrd_file->fd);
- return (-1);
+ goto err_close;/*XXX: should use err_free_all_ds_namv */
}
#endif
#endif
}
- rrd_free(&rrd);
#ifdef HAVE_POSIX_FADVISE
/* and just to be sure we drop everything except the header at the end */
if (0 !=
POSIX_FADV_DONTNEED)) {
rrd_set_error("setting POSIX_FADV_DONTNEED on '%s': %s", filename,
rrd_strerror(errno));
- close(rrd_file->fd);
- return (-1);
+ goto err_free; /*XXX: should use err_free_all_ds_namv */
}
#endif
- close(rrd_file->fd);
+ rrd_close(rrd_file);
return (0);
+err_free_data:
+ free(*data);
+ *data = NULL;
+err_free_all_ds_namv:
+ for (i = 0; (unsigned long)i < rrd.stat_head->ds_cnt; ++i)
+ free((*ds_namv)[i]);
+err_free_ds_namv:
+ free(*ds_namv);
+err_close:
+ rrd_close(rrd_file);
+err_free:
+ rrd_free(&rrd);
+ return (-1);
}
diff --git a/src/rrd_first.c b/src/rrd_first.c
index 0bd3f459ab9d7ac22945c1f2a1e13e5abf17f00f..bb869471574d3f657fbb5c335227885c9ca1e403 100644 (file)
--- a/src/rrd_first.c
+++ b/src/rrd_first.c
const int rraindex)
{
off_t rra_start, timer;
- time_t then;
+ time_t then = -1;
rrd_t rrd;
rrd_file_t *rrd_file;
rrd_file = rrd_open(filename, &rrd, RRD_READONLY);
if (rrd_file == NULL) {
- rrd_set_error("could not open RRD");
- return (-1);
+ goto err_free;
}
if ((rraindex < 0) || (rraindex >= (int) rrd.stat_head->rra_cnt)) {
rrd_set_error("invalid rraindex number");
- rrd_free(&rrd);
- close(rrd_file->fd);
- return (-1);
+ goto err_close;
}
rra_start = rrd_file->header_len;
rrd.live_head->last_up %
(rrd.rra_def[rraindex].pdp_cnt * rrd.stat_head->pdp_step)) +
(timer * rrd.rra_def[rraindex].pdp_cnt * rrd.stat_head->pdp_step);
-
- rrd_free(&rrd);
- close(rrd_file->fd);
+err_close:
rrd_close(rrd_file);
+err_free:
+ rrd_free(&rrd);
return (then);
}
diff --git a/src/rrd_info.c b/src/rrd_info.c
index d0d9db5b456dcfe992076a097c5225fc43a7cf44..e5d195fdbcf3576bfef9ec86ec8485e5772645db 100644 (file)
--- a/src/rrd_info.c
+++ b/src/rrd_info.c
{
unsigned int i, ii = 0;
rrd_t rrd;
- info_t *data, *cd;
+ info_t *data = NULL, *cd;
infoval info;
rrd_file_t *rrd_file;
enum cf_en current_cf;
enum dst_en current_ds;
rrd_file = rrd_open(filename, &rrd, RRD_READONLY);
- if (rrd_file == NULL) {
- return (NULL);
- }
- close(rrd_file->fd);
+ if (rrd_file == NULL)
+ goto err_free;
info.u_str = filename;
cd = info_push(NULL, sprintf_alloc("filename"), RD_I_STR, info);
}
}
}
- rrd_free(&rrd);
+
rrd_close(rrd_file);
+err_free:
+ rrd_free(&rrd);
return (data);
-
}
diff --git a/src/rrd_last.c b/src/rrd_last.c
index 42a807597de58d435a35948b1450fbc1a0d993aa..90da610ffaef42f041de5c98b5d8530efe6a9dc0 100644 (file)
--- a/src/rrd_last.c
+++ b/src/rrd_last.c
time_t rrd_last_r(
const char *filename)
{
- time_t lastup;
+ time_t lastup = -1;
rrd_file_t *rrd_file;
rrd_t rrd;
rrd_file = rrd_open(filename, &rrd, RRD_READONLY);
- if (rrd_file == NULL)
- return (-1);
-
- lastup = rrd.live_head->last_up;
+ if (rrd_file != NULL) {
+ lastup = rrd.live_head->last_up;
+ rrd_close(rrd_file);
+ }
rrd_free(&rrd);
- close(rrd_file->fd);
- rrd_close(rrd_file);
return (lastup);
}
diff --git a/src/rrd_lastupdate.c b/src/rrd_lastupdate.c
index 79274b55c929c727e27cd5d381b507498618fcd9..046a1733196b3606209b56c17441cc4050ecde2b 100644 (file)
--- a/src/rrd_lastupdate.c
+++ b/src/rrd_lastupdate.c
if (argc < 2) {
rrd_set_error("please specify an rrd");
- return -1;
+ goto err_out;
}
filename = argv[1];
rrd_file = rrd_open(filename, &rrd, RRD_READONLY);
if (rrd_file == NULL)
- return (-1);
+ goto err_free;
*last_update = rrd.live_head->last_up;
*ds_cnt = rrd.stat_head->ds_cnt;
if (((*ds_namv) =
(char **) malloc(rrd.stat_head->ds_cnt * sizeof(char *))) == NULL) {
rrd_set_error("malloc fetch ds_namv array");
- rrd_free(&rrd);
- return (-1);
+ goto err_close;
}
if (((*last_ds) =
(char **) malloc(rrd.stat_head->ds_cnt * sizeof(char *))) == NULL) {
rrd_set_error("malloc fetch last_ds array");
- rrd_free(&rrd);
- free(*ds_namv);
- return (-1);
+ goto err_free_ds_namv;
}
for (i = 0; i < rrd.stat_head->ds_cnt; i++) {
}
rrd_free(&rrd);
- close(rrd_file->fd);
rrd_close(rrd_file);
return (0);
+
+err_free_ds_namv:
+ free(*ds_namv);
+err_close:
+ rrd_close(rrd_file);
+err_free:
+ rrd_free(&rrd);
+err_out:
+ return (-1);
}
diff --git a/src/rrd_open.c b/src/rrd_open.c
index c986f750beca7bec9fb3f0cba5c5a488cfda17d2..e18209175e7ea8e5f63d800e3047a269c940a8d1 100644 (file)
--- a/src/rrd_open.c
+++ b/src/rrd_open.c
/* DEBUG 2 prints information obtained via mincore(2) */
// #define DEBUG 2
-/* do not calculate exact madvise hints but assume 2 pages for headers and
+/* do not calculate exact madvise hints but assume 1 page for headers and
* set DONTNEED for the rest, which is assumed to be data */
-//#define TWO_PAGES 1
+//#define ONE_PAGE 1
/* Avoid calling madvise on areas that were already hinted. May be benefical if
* your syscalls are very slow */
//#define CHECK_MADVISE_OVERLAPS 1
madvise((_start), (_off), (_hint))
#endif
-/* open a database file, return its header and an open filehandle */
-/* positioned to the first cdp in the first rra */
+/* Open a database file, return its header and an open filehandle,
+ * positioned to the first cdp in the first rra.
+ * In the error path of rrd_open, only rrd_free(&rrd) has to be called
+ * before returning an error. Do not call rrd_close upon failure of rrd_open.
+ */
rrd_file_t *rrd_open(
const char *const file_name,
#endif
off_t offset = 0;
struct stat statb;
- rrd_file_t *rrd_file = malloc(sizeof(rrd_file_t));
+ rrd_file_t *rrd_file = NULL;
+ rrd_init(rrd);
+ rrd_file = malloc(sizeof(rrd_file_t));
if (rrd_file == NULL) {
rrd_set_error("allocating rrd_file descriptor for '%s'", file_name);
return NULL;
}
memset(rrd_file, 0, sizeof(rrd_file_t));
- rrd_init(rrd);
+
#ifdef DEBUG
if ((rdwr & (RRD_READONLY | RRD_READWRITE)) ==
(RRD_READONLY | RRD_READWRITE)) {
goto out_done;
}
/* We do not need to read anything in for the moment */
-#ifndef TWO_PAGES
+#ifndef ONE_PAGE
_madvise(data, rrd_file->file_len, MADV_DONTNEED);
// _madvise(data, rrd_file->file_len, MADV_RANDOM);
#else
/* alternatively: keep 2 pages worth of data, likely headers,
* don't need the rest. */
- _madvise(data, _page_size * 2, MADV_WILLNEED | MADV_SEQUENTIAL);
- _madvise(data + _page_size * 2, (rrd_file->file_len >= _page_size * 2)
- ? rrd_file->file_len - _page_size * 2 : 0, MADV_DONTNEED);
+ _madvise(data, _page_size, MADV_WILLNEED | MADV_SEQUENTIAL);
+ _madvise(data + _page_size, (rrd_file->file_len >= _page_size)
+ ? rrd_file->file_len - _page_size : 0, MADV_DONTNEED);
#endif
#endif
-#if defined USE_MADVISE && !defined TWO_PAGES
+#if defined USE_MADVISE && !defined ONE_PAGE
/* the stat_head will be needed soonish, so hint accordingly */
// too finegrained to calc the individual sizes, just keep 2 pages worth of hdr
_madvise(data + PAGE_ALIGN_DOWN(offset), PAGE_ALIGN(sizeof(stat_head_t)),
rrd->stat_head->version);
goto out_nullify_head;
}
-#if defined USE_MADVISE && !defined TWO_PAGES
+#if defined USE_MADVISE && !defined ONE_PAGE
/* the ds_def will be needed soonish, so hint accordingly */
_madvise(data + PAGE_ALIGN_DOWN(offset),
PAGE_ALIGN(sizeof(ds_def_t) * rrd->stat_head->ds_cnt),
__rrd_read(rrd->ds_def, ds_def_t,
rrd->stat_head->ds_cnt);
-#if defined USE_MADVISE && !defined TWO_PAGES
+#if defined USE_MADVISE && !defined ONE_PAGE
/* the rra_def will be needed soonish, so hint accordingly */
_madvise(data + PAGE_ALIGN_DOWN(offset),
PAGE_ALIGN(sizeof(rra_def_t) * rrd->stat_head->rra_cnt),
#endif
rrd->live_head->last_up_usec = 0;
} else {
-#if defined USE_MADVISE && !defined TWO_PAGES
+#if defined USE_MADVISE && !defined ONE_PAGE
/* the live_head will be needed soonish, so hint accordingly */
_madvise(data + PAGE_ALIGN_DOWN(offset),
PAGE_ALIGN(sizeof(live_head_t)), MADV_WILLNEED);
{
int ret;
-#if defined HAVE_MMAP
+#if defined HAVE_MMAP || defined DEBUG
ssize_t _page_size = sysconf(_SC_PAGESIZE);
#endif
#if defined DEBUG && DEBUG > 1
off_t off;
unsigned char *vec;
- off =
- rrd_file->file_len +
- ((rrd_file->file_len + sysconf(_SC_PAGESIZE) -
- 1) / sysconf(_SC_PAGESIZE));
+ off = rrd_file->file_len +
+ ((rrd_file->file_len + _page_size - 1) / _page_size);
vec = malloc(off);
if (vec != NULL) {
memset(vec, 0, off);
#endif /* DEBUG */
#ifdef USE_MADVISE
-#ifdef TWO_PAGES
-//XXX: ?
- /* Keep 2 pages worth of headers around, round up to next page boundary. */
+#ifdef ONE_PAGE
+ /* Keep headers around, round up to next page boundary. */
ret =
PAGE_ALIGN(rrd_file->header_len % _page_size + rrd_file->header_len);
if (rrd_file->file_len > ret)
ret = munmap(rrd_file->file_start, rrd_file->file_len);
if (ret != 0)
rrd_set_error("munmap rrd_file: %s", rrd_strerror(errno));
-#else
- ret = 0;
#endif
-// ret = close(rrd_file->fd);
-// if (ret != 0)
-// rrd_set_error("closing file: %s", rrd_strerror(errno));
+ ret = close(rrd_file->fd);
+ if (ret != 0)
+ rrd_set_error("closing file: %s", rrd_strerror(errno));
free(rrd_file);
rrd_file = NULL;
return ret;
/* free RRD header data. */
+#ifdef HAVE_MMAP
+inline void rrd_free(
+ rrd_t UNUSED(*rrd)) {}
+#else
void rrd_free(
- rrd_t UNUSED(*rrd))
+ rrd_t *rrd)
{
-#ifndef HAVE_MMAP
if (atoi(rrd->stat_head->version) < 3)
free(rrd->live_head);
free(rrd->stat_head);
free(rrd->pdp_prep);
free(rrd->cdp_prep);
free(rrd->rrd_value);
-#endif
}
+#endif
/* routine used by external libraries to free memory allocated by
diff --git a/src/rrd_resize.c b/src/rrd_resize.c
index 11efcdaac7617f3fffa4cc768c48be29dfb73b60..09927df037999531070c68dafdebbf2138e6e3b7 100644 (file)
--- a/src/rrd_resize.c
+++ b/src/rrd_resize.c
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);
}
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);
}
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 */
sizeof(rra_ptr_t) * rrdnew.stat_head->rra_cnt);
rrd_free(&rrdold);
- close(rrd_file->fd);
rrd_close(rrd_file);
rrd_free(&rrdnew);
- close(rrd_out_file->fd);
rrd_close(rrd_out_file);
return (0);
diff --git a/src/rrd_tune.c b/src/rrd_tune.c
index 680e5587e7d75e27ff631f795f2dc8c34bb708f6..91f6409ada384e79093e9ea28d20b90ff92284ce 100644 (file)
--- a/src/rrd_tune.c
+++ b/src/rrd_tune.c
rrd_file = rrd_open(argv[1], &rrd, RRD_READWRITE);
if (rrd_file == NULL) {
+ rrd_free(&rrd);
return -1;
}
&heartbeat)) != 2) {
rrd_set_error("invalid arguments for heartbeat");
rrd_free(&rrd);
- close(rrd_file->fd);
+ rrd_close(rrd_file);
return -1;
}
if ((ds = ds_match(&rrd, ds_nam)) == -1) {
rrd_free(&rrd);
- close(rrd_file->fd);
+ rrd_close(rrd_file);
return -1;
}
rrd.ds_def[ds].par[DS_mrhb_cnt].u_cnt = heartbeat;
sscanf(optarg, DS_NAM_FMT ":%lf", ds_nam, &min)) < 1) {
rrd_set_error("invalid arguments for minimum ds value");
rrd_free(&rrd);
- close(rrd_file->fd);
+ rrd_close(rrd_file);
return -1;
}
if ((ds = ds_match(&rrd, ds_nam)) == -1) {
rrd_free(&rrd);
- close(rrd_file->fd);
+ rrd_close(rrd_file);
return -1;
}
sscanf(optarg, DS_NAM_FMT ":%lf", ds_nam, &max)) < 1) {
rrd_set_error("invalid arguments for maximum ds value");
rrd_free(&rrd);
- close(rrd_file->fd);
+ rrd_close(rrd_file);
return -1;
}
if ((ds = ds_match(&rrd, ds_nam)) == -1) {
rrd_free(&rrd);
- close(rrd_file->fd);
+ rrd_close(rrd_file);
return -1;
}
if (matches == 1)
sscanf(optarg, DS_NAM_FMT ":" DST_FMT, ds_nam, dst)) != 2) {
rrd_set_error("invalid arguments for data source type");
rrd_free(&rrd);
- close(rrd_file->fd);
+ rrd_close(rrd_file);
return -1;
}
if ((ds = ds_match(&rrd, ds_nam)) == -1) {
rrd_free(&rrd);
- close(rrd_file->fd);
+ rrd_close(rrd_file);
return -1;
}
if ((int) dst_conv(dst) == -1) {
rrd_free(&rrd);
- close(rrd_file->fd);
+ rrd_close(rrd_file);
return -1;
}
strncpy(rrd.ds_def[ds].dst, dst, DST_SIZE - 1);
ds_new)) != 2) {
rrd_set_error("invalid arguments for data source type");
rrd_free(&rrd);
- close(rrd_file->fd);
+ rrd_close(rrd_file);
return -1;
}
if ((ds = ds_match(&rrd, ds_nam)) == -1) {
rrd_free(&rrd);
- close(rrd_file->fd);
+ rrd_close(rrd_file);
return -1;
}
strncpy(rrd.ds_def[ds].ds_nam, ds_new, DS_NAM_SIZE - 1);
if (sscanf(optarg, DS_NAM_FMT, ds_nam) != 1) {
rrd_set_error("invalid argument for aberrant-reset");
rrd_free(&rrd);
- close(rrd_file->fd);
+ rrd_close(rrd_file);
return -1;
}
if ((ds = ds_match(&rrd, ds_nam)) == -1) {
/* ds_match handles it own errors */
rrd_free(&rrd);
- close(rrd_file->fd);
+ rrd_close(rrd_file);
return -1;
}
reset_aberrant_coefficients(&rrd, rrd_file, (unsigned long) ds);
if (rrd_test_error()) {
rrd_free(&rrd);
- close(rrd_file->fd);
+ rrd_close(rrd_file);
return -1;
}
break;
else
rrd_set_error("unknown option '%s'", argv[optind - 1]);
rrd_free(&rrd);
- close(rrd_file->fd);
+ rrd_close(rrd_file);
return -1;
}
}
free(buffer);
}
}
- close(rrd_file->fd);
+ rrd_close(rrd_file);
rrd_free(&rrd);
return 0;
}
diff --git a/src/rrd_update.c b/src/rrd_update.c
index 6ef5d3fe4ed96728e8a9da76001015de6f2942ef..18db8e7ceb02c5e0cba86f12aa9bb6bc330e8ba8 100644 (file)
--- a/src/rrd_update.c
+++ b/src/rrd_update.c
rrd_file = rrd_open(filename, &rrd, RRD_READWRITE);
if (rrd_file == NULL) {
- goto err_out;
+ goto err_free;
}
/* initialize time */
free(pdp_temp);
free(tmpl_idx);
rrd_free(&rrd);
- close(rrd_file->fd);
+ rrd_close(rrd_file);
return (-1);
}
#ifdef USE_MADVISE
}
rrd_free(&rrd);
- close(rrd_file->fd);
rrd_close(rrd_file);
free(pdp_new);
err_free_updvals:
free(updvals);
err_close:
- rrd_free(&rrd);
- close(rrd_file->fd);
rrd_close(rrd_file);
+ err_free:
+ rrd_free(&rrd);
err_out:
return (-1);
}