daniel has uploaded this change for review.
hnbgw_hnbap: Fix memory leaks in HNBAP handling
* Use osmo_stream closed_cb to call hnb_context_release() in all cases
* Also call hnbap_free_hnbregisterrequesties() when sending hnb register
reject
Related: OS#5656
Change-Id: I3ba02b0939413c67bc8088ea1a8f2252fc2bda31
---
M src/osmo-hnbgw/hnbgw.c
M src/osmo-hnbgw/hnbgw_hnbap.c
2 files changed, 14 insertions(+), 6 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-hnbgw refs/changes/99/29199/1
diff --git a/src/osmo-hnbgw/hnbgw.c b/src/osmo-hnbgw/hnbgw.c
index fe503f8..b33b6d5 100644
--- a/src/osmo-hnbgw/hnbgw.c
+++ b/src/osmo-hnbgw/hnbgw.c
@@ -256,11 +256,10 @@
return 0;
} else if (rc < 0) {
LOGHNB(hnb, DMAIN, LOGL_ERROR, "Error during sctp_recvmsg()\n");
- /* FIXME: clean up after disappeared HNB */
- hnb_context_release(hnb);
+ osmo_stream_srv_destroy(conn);
goto out;
} else if (rc == 0) {
- hnb_context_release(hnb);
+ osmo_stream_srv_destroy(conn);
rc = -1;
goto out;
@@ -294,6 +293,15 @@
return rc;
}
+static int hnb_closed_cb(struct osmo_stream_srv *conn) {
+ struct hnb_context *hnb = osmo_stream_srv_get_data(conn);
+
+ if (hnb)
+ hnb_context_release(hnb);
+
+ return 0;
+}
+
struct hnb_context *hnb_context_alloc(struct hnb_gw *gw, struct osmo_stream_srv_link *link, int new_fd)
{
struct hnb_context *ctx;
@@ -304,7 +312,7 @@
INIT_LLIST_HEAD(&ctx->map_list);
ctx->gw = gw;
- ctx->conn = osmo_stream_srv_create(tall_hnb_ctx, link, new_fd, hnb_read_cb, NULL, ctx);
+ ctx->conn = osmo_stream_srv_create(tall_hnb_ctx, link, new_fd, hnb_read_cb, hnb_closed_cb, ctx);
if (!ctx->conn) {
LOGP(DMAIN, LOGL_INFO, "error while creating connection\n");
talloc_free(ctx);
@@ -351,8 +359,7 @@
context_map_deactivate(map);
}
ue_context_free_by_hnb(ctx->gw, ctx);
-
- osmo_stream_srv_destroy(ctx->conn);
+ osmo_stream_srv_set_data(ctx->conn, NULL);
talloc_free(ctx);
}
diff --git a/src/osmo-hnbgw/hnbgw_hnbap.c b/src/osmo-hnbgw/hnbgw_hnbap.c
index 4c3a5c0..2a35491 100644
--- a/src/osmo-hnbgw/hnbgw_hnbap.c
+++ b/src/osmo-hnbgw/hnbgw_hnbap.c
@@ -426,6 +426,7 @@
"MCC=%u,MNC=%u,LAC=%u,RAC=%u,SAC=%u,CID=%u from %s\n",
ctx->id.mcc, ctx->id.mnc, ctx->id.lac, ctx->id.rac, ctx->id.sac, ctx->id.cid, name);
talloc_free(name);
+ hnbap_free_hnbregisterrequesties(&ies);
return hnbgw_tx_hnb_register_rej(ctx);
}
}
To view, visit change 29199. To unsubscribe, or for help writing mail filters, visit settings.