pespin has submitted this change. (
https://gerrit.osmocom.org/c/osmo-hnbgw/+/40267?usp=email )
Change subject: cnlink: Cleanup talloc tree
......................................................................
cnlink: Cleanup talloc tree
Previous logic allocating structs was a big convoluted regarding order
of assignments, which then even required a taloc_steal.
Since recently the struct hnbgw_cnpool is a talloc context, and struct
hnbgw_cnlink are allocated as being part of a cnpool, so clean up the
talloc tree by having cnlink under cnpool.
Finally, put the cnlink_fsm and the cnlink counters under the hnbgw_cnlink
talloc context, where they belong.
Change-Id: I90c22f2a2932ede7103c66f2263e72ac2fdae497
---
M src/osmo-hnbgw/cnlink.c
1 file changed, 13 insertions(+), 13 deletions(-)
Approvals:
Jenkins Builder: Verified
pespin: Looks good to me, approved
diff --git a/src/osmo-hnbgw/cnlink.c b/src/osmo-hnbgw/cnlink.c
index 2ba748c..19f1d3d 100644
--- a/src/osmo-hnbgw/cnlink.c
+++ b/src/osmo-hnbgw/cnlink.c
@@ -163,12 +163,10 @@
struct hnbgw_cnlink *hnbgw_cnlink_alloc(struct hnbgw_cnpool *cnpool, int nr)
{
- struct osmo_fsm_inst *fi;
struct hnbgw_cnlink *cnlink;
const struct rate_ctr_group_desc *ctrg_desc;
OSMO_ASSERT(cnpool);
- char *name = talloc_asprintf(OTC_SELECT, "%s-%d", cnpool->peer_name, nr);
switch (cnpool->domain) {
case DOMAIN_CS:
@@ -181,28 +179,25 @@
OSMO_ASSERT(0);
}
-
- fi = osmo_fsm_inst_alloc(&cnlink_fsm, g_hnbgw, NULL, LOGL_DEBUG, name);
- OSMO_ASSERT(fi);
- cnlink = talloc_zero(g_hnbgw, struct hnbgw_cnlink);
- fi->priv = cnlink;
-
+ cnlink = talloc_zero(cnpool, struct hnbgw_cnlink);
+ OSMO_ASSERT(cnlink);
*cnlink = (struct hnbgw_cnlink){
- .name = name,
.pool = cnpool,
- .fi = fi,
.nr = nr,
.vty = {
/* VTY config defaults for the new cnlink */
.nri_ranges = osmo_nri_ranges_alloc(cnlink),
},
.allow_attach = true,
- .ctrs = rate_ctr_group_alloc(g_hnbgw, ctrg_desc, nr),
+ .ctrs = rate_ctr_group_alloc(cnlink, ctrg_desc, nr),
};
- talloc_steal(cnlink, name);
+ cnlink->name = talloc_asprintf(cnlink, "%s-%d", cnpool->peer_name, nr);
INIT_LLIST_HEAD(&cnlink->map_list);
INIT_LLIST_HEAD(&cnlink->paging);
+ cnlink->fi = osmo_fsm_inst_alloc(&cnlink_fsm, cnlink, cnlink, LOGL_DEBUG,
cnlink->name);
+ OSMO_ASSERT(cnlink->fi);
+
llist_add_tail(&cnlink->entry, &cnpool->cnlinks);
LOG_CNLINK(cnlink, DCN, LOGL_DEBUG, "allocated\n");
@@ -229,9 +224,14 @@
{
if (!cnlink)
return;
- osmo_fsm_inst_term(cnlink->fi, OSMO_FSM_TERM_REQUEST, NULL);
+
if (cnlink->hnbgw_sccp_user)
hnbgw_cnlink_drop_sccp(cnlink);
+
+ osmo_fsm_inst_term(cnlink->fi, OSMO_FSM_TERM_REQUEST, NULL);
+ cnlink->fi = NULL;
+ rate_ctr_group_free(cnlink->ctrs);
+ llist_del(&cnlink->entry);
talloc_free(cnlink);
}
--
To view, visit
https://gerrit.osmocom.org/c/osmo-hnbgw/+/40267?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: osmo-hnbgw
Gerrit-Branch: master
Gerrit-Change-Id: I90c22f2a2932ede7103c66f2263e72ac2fdae497
Gerrit-Change-Number: 40267
Gerrit-PatchSet: 4
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>