summaryrefslogtreecommitdiffstats
path: root/src/rrd.c
diff options
context:
space:
mode:
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2017-01-01 19:34:43 +0200
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2017-01-01 19:34:43 +0200
commitd4c83d0cba04990c34d808641dc926b22181f82e (patch)
tree8bae97e4834dcc606c86a546c796dbba6d4c9aca /src/rrd.c
parent3e1a333c5749373c0471ad026427e83761fbf4c4 (diff)
strict checking on binary tree operations
Diffstat (limited to 'src/rrd.c')
-rw-r--r--src/rrd.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/rrd.c b/src/rrd.c
index 0b0da71d04..9f42b7b1b7 100644
--- a/src/rrd.c
+++ b/src/rrd.c
@@ -118,7 +118,7 @@ RRDFAMILY *rrdfamily_create(const char *id) {
RRDFAMILY *ret = rrdfamily_index_add(&localhost, rc);
if(ret != rc)
- fatal("INTERNAL ERROR: Expected to INSERT RRDFAMILY '%s' into index, but inserted '%s'.", rc->family, (ret)?ret->family:"NONE");
+ fatal("RRDFAMILY: INTERNAL ERROR: Expected to INSERT RRDFAMILY '%s' into index, but inserted '%s'.", rc->family, (ret)?ret->family:"NONE");
}
rc->use_count++;
@@ -130,10 +130,10 @@ void rrdfamily_free(RRDFAMILY *rc) {
if(!rc->use_count) {
RRDFAMILY *ret = rrdfamily_index_del(&localhost, rc);
if(ret != rc)
- fatal("INTERNAL ERROR: Expected to DELETE RRDFAMILY '%s' from index, but deleted '%s'.", rc->family, (ret)?ret->family:"NONE");
+ fatal("RRDFAMILY: INTERNAL ERROR: Expected to DELETE RRDFAMILY '%s' from index, but deleted '%s'.", rc->family, (ret)?ret->family:"NONE");
if(rc->variables_root_index.avl_tree.root != NULL)
- fatal("INTERNAL ERROR: Variables index of RRDFAMILY '%s' that is freed, is not empty.", rc->family);
+ fatal("RRDFAMILY: INTERNAL ERROR: Variables index of RRDFAMILY '%s' that is freed, is not empty.", rc->family);
freez((void *)rc->family);
freez(rc);
@@ -222,8 +222,8 @@ static int rrddim_compare(void* a, void* b) {
else return strcmp(((RRDDIM *)a)->id, ((RRDDIM *)b)->id);
}
-#define rrddim_index_add(st, rd) avl_insert_lock(&((st)->dimensions_index), (avl *)(rd))
-#define rrddim_index_del(st,rd ) avl_remove_lock(&((st)->dimensions_index), (avl *)(rd))
+#define rrddim_index_add(st, rd) (RRDDIM *)avl_insert_lock(&((st)->dimensions_index), (avl *)(rd))
+#define rrddim_index_del(st,rd ) (RRDDIM *)avl_remove_lock(&((st)->dimensions_index), (avl *)(rd))
static RRDDIM *rrddim_index_find(RRDSET *st, const char *id, uint32_t hash) {
RRDDIM tmp;
@@ -381,7 +381,8 @@ void rrdset_set_name(RRDSET *st, const char *name)
rrddimvar_rename_all(rd);
pthread_rwlock_unlock(&st->rwlock);
- rrdset_index_add_name(&localhost, st);
+ if(unlikely(rrdset_index_add_name(&localhost, st) != st))
+ error("RRDSET: INTERNAL ERROR: attempted to index duplicate chart name '%s'", st->name);
}
// ----------------------------------------------------------------------------
@@ -634,7 +635,8 @@ RRDSET *rrdset_create(const char *type, const char *id, const char *name, const
rrdsetvar_create(st, "update_every", RRDVAR_TYPE_INT, &st->update_every, 0);
}
- rrdset_index_add(&localhost, st);
+ if(unlikely(rrdset_index_add(&localhost, st) != st))
+ error("RRDSET: INTERNAL ERROR: attempt to index duplicate chart '%s'", st->id);
rrdsetcalc_link_matching(st);
rrdcalctemplate_link_matching(st);
@@ -777,7 +779,8 @@ RRDDIM *rrddim_add(RRDSET *st, const char *id, const char *name, long multiplier
pthread_rwlock_unlock(&st->rwlock);
- rrddim_index_add(st, rd);
+ if(unlikely(rrddim_index_add(st, rd) != rd))
+ error("RRDDIM: INTERNAL ERROR: attempt to index duplicate dimension '%s' on chart '%s'", rd->id, st->id);
return(rd);
}
@@ -816,7 +819,8 @@ void rrddim_free(RRDSET *st, RRDDIM *rd)
while(rd->variables)
rrddimvar_free(rd->variables);
- rrddim_index_del(st, rd);
+ if(unlikely(rrddim_index_del(st, rd) != rd))
+ error("RRDDIM: INTERNAL ERROR: attempt to remove from index dimension '%s' on chart '%s', removed a different dimension.", rd->id, st->id);
// free(rd->annotations);
if(rd->mapped == RRD_MEMORY_MODE_SAVE) {
@@ -857,7 +861,8 @@ void rrdset_free_all(void)
while(st->dimensions)
rrddim_free(st, st->dimensions);
- rrdset_index_del(&localhost, st);
+ if(unlikely(rrdset_index_del(&localhost, st) != st))
+ error("RRDSET: INTERNAL ERROR: attempt to remove from index chart '%s', removed a different chart.", st->id);
st->rrdfamily->use_count--;
if(!st->rrdfamily->use_count)