rate_ctr: fix mem leak for mangled desc
Using the NULL context creates mem leaks that bother sanitizer builds.
Allocate as talloc "child" of the rate_ctr_group, so that the mangled desc (if
any) gets freed when the rate_ctr group is freed.
Remove the comment concerning osmo-msc: the way to fix the unexpected talloc
state in osmo-msc tests is to have no invalid rate counter names in osmo-msc.
See Ib1db8e3dc6c833174f1b0b1ca051b0861f477408 (osmo-msc).
Change-Id: Ief9abfeb78b7706200bcc6aaa5dcb04fbeaa9b5b
diff --git a/src/rate_ctr.c b/src/rate_ctr.c
index 5464490..477339f 100644
--- a/src/rate_ctr.c
+++ b/src/rate_ctr.c
@@ -190,15 +190,6 @@
unsigned int size;
struct rate_ctr_group *group;
- /* attempt to mangle all '.' in identifiers to ':' for backwards compat */
- if (!rate_ctrl_group_desc_validate(desc, true)) {
- /* don't use 'ctx' here as it would screw up memory leak debugging e.g.
- * in osmo-msc */
- desc = rate_ctr_group_desc_mangle(NULL, desc);
- if (!desc)
- return NULL;
- }
-
size = sizeof(struct rate_ctr_group) +
desc->num_ctr * sizeof(struct rate_ctr);
@@ -209,6 +200,15 @@
if (!group)
return NULL;
+ /* attempt to mangle all '.' in identifiers to ':' for backwards compat */
+ if (!rate_ctrl_group_desc_validate(desc, true)) {
+ desc = rate_ctr_group_desc_mangle(group, desc);
+ if (!desc) {
+ talloc_free(group);
+ return NULL;
+ }
+ }
+
group->desc = desc;
group->idx = idx;