summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/rate_ctr.c3
-rw-r--r--tests/stats/stats_test.c7
2 files changed, 9 insertions, 1 deletions
diff --git a/src/rate_ctr.c b/src/rate_ctr.c
index 477339f2..c27ac68e 100644
--- a/src/rate_ctr.c
+++ b/src/rate_ctr.c
@@ -190,6 +190,9 @@ struct rate_ctr_group *rate_ctr_group_alloc(void *ctx,
unsigned int size;
struct rate_ctr_group *group;
+ if (rate_ctr_get_group_by_name_idx(desc->group_name_prefix, idx))
+ return NULL; /* group already exist */
+
size = sizeof(struct rate_ctr_group) +
desc->num_ctr * sizeof(struct rate_ctr);
diff --git a/tests/stats/stats_test.c b/tests/stats/stats_test.c
index b302b374..35faf9a6 100644
--- a/tests/stats/stats_test.c
+++ b/tests/stats/stats_test.c
@@ -311,7 +311,7 @@ static void test_reporting()
{
struct osmo_stats_reporter *srep1, *srep2, *srep;
struct osmo_stat_item_group *statg1, *statg2;
- struct rate_ctr_group *ctrg1, *ctrg2, *ctrg3;
+ struct rate_ctr_group *ctrg1, *ctrg2, *ctrg3, *ctrg_dup;
void *stats_ctx = talloc_named_const(NULL, 1, "stats test context");
int rc;
@@ -327,6 +327,11 @@ static void test_reporting()
OSMO_ASSERT(ctrg1 != NULL);
ctrg2 = rate_ctr_group_alloc(stats_ctx, &ctrg_desc, 2);
OSMO_ASSERT(ctrg2 != NULL);
+
+ ctrg_dup = rate_ctr_group_alloc(stats_ctx, &ctrg_desc, 2);
+ if (ctrg_dup != NULL && ctrg2 != NULL)
+ printf("FAIL: successfully allocated already existing counter group!\n");
+
ctrg3 = rate_ctr_group_alloc(stats_ctx, &ctrg_desc_dot, 3);
OSMO_ASSERT(ctrg3 != NULL);