hnb_context_release(): Make sure assigned conn is freed

Otherwise, some paths calling hnb_context_release() (like failing to
transmit HNB-REGISTER-REJECT) would end up with a conn object alive with
no assigned hnb_context, which is something not wanted.

This way an alive conn object always has an associated hnb_context, and
they are only disassociated during synchronous release path.

Related: OS#5676
Change-Id: I44fea7ec74f14e0458861c92da4acf685ff695c1
This commit is contained in:
Pau Espin 2022-09-13 12:25:05 +02:00
parent 96c712570a
commit 930ed702b6
1 changed files with 13 additions and 3 deletions

View File

@ -300,9 +300,14 @@ out:
static int hnb_closed_cb(struct osmo_stream_srv *conn)
{
struct hnb_context *hnb = osmo_stream_srv_get_data(conn);
if (!hnb)
return 0; /* hnb_context is being freed, nothing do be done */
if (hnb)
hnb_context_release(hnb);
/* hnb: conn became broken, let's release the associated hnb.
* conn object is being freed after closed_cb(), so unassign it from hnb
* if available to avoid it freeing it again: */
hnb->conn = NULL;
hnb_context_release(hnb);
return 0;
}
@ -364,7 +369,12 @@ void hnb_context_release(struct hnb_context *ctx)
context_map_deactivate(map);
}
ue_context_free_by_hnb(ctx->gw, ctx);
osmo_stream_srv_set_data(ctx->conn, NULL);
if (ctx->conn) { /* we own a conn, we must free it: */
/* Avoid our closed_cb calling hnb_context_release() again: */
osmo_stream_srv_set_data(ctx->conn, NULL);
osmo_stream_srv_destroy(ctx->conn);
} /* else: we are called from closed_cb, so conn is being freed separately */
talloc_free(ctx);
}