mgcp_ratectr: do not set talloc destructor on library allocated item

The rate counter and stats item groups, which are allocated in
mgcp_ratectr.c are freed using a talloc destructor that is set in the
context of the item we just allocated using the stats / rate counter API
functions. When we do that, we risk overwriting an already existing
talloc destructor. Lets instead implement own free functions and set
those as talloc_destructor from above (trunk and MGCP config)

Change-Id: Ifc5091e9f95cc721e58d1eb2e55b97102c497706
Related: OS#5201
diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c
index b7368b2..88f1bd0 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -1583,6 +1583,13 @@
 				    trunk->keepalive_interval, 0);
 }
 
+/* Free config, this function is automatically called by talloc_free when the configuration is freed. */
+static int config_free_talloc_destructor(struct mgcp_config *cfg)
+{
+	mgcp_ratectr_global_free(cfg);
+	return 0;
+}
+
 /*! allocate configuration with default values.
  *  (called once at startup by main function) */
 struct mgcp_config *mgcp_config_alloc(void)
@@ -1621,6 +1628,7 @@
 	}
 
 	mgcp_ratectr_global_alloc(cfg);
+	talloc_set_destructor(cfg, config_free_talloc_destructor);
 
 	return cfg;
 }