mgw: Release endpoint after last conn times out
Otherwise some state is kept, like the previous CallId, which may then
provoke issues next time the endpoint is to be used.
Change-Id: I3ac4f4542c1c8c877127c64acce6c82b458f697f
diff --git a/src/libosmo-mgcp/mgcp_conn.c b/src/libosmo-mgcp/mgcp_conn.c
index 328e580..6424dcb 100644
--- a/src/libosmo-mgcp/mgcp_conn.c
+++ b/src/libosmo-mgcp/mgcp_conn.c
@@ -199,7 +199,7 @@
/* Initialize watchdog */
osmo_timer_setup(&conn->watchdog, mgcp_conn_watchdog_cb, conn);
mgcp_conn_watchdog_kick(conn);
- llist_add(&conn->entry, &endp->conns);
+ mgcp_endp_add_conn(endp, conn);
return conn;
}
@@ -289,12 +289,6 @@
if (!conn)
return;
- /* Run endpoint cleanup action. By this we inform the endpoint about
- * the removal of the connection and allow it to clean up its inner
- * state accordingly */
- if (endp->type->cleanup_cb)
- endp->type->cleanup_cb(endp, conn);
-
switch (conn->type) {
case MGCP_CONN_TYPE_RTP:
aggregate_rtp_conn_stats(endp, &conn->u.rtp);
@@ -308,7 +302,8 @@
}
osmo_timer_del(&conn->watchdog);
- llist_del(&conn->entry);
+ mgcp_endp_remove_conn(endp, conn);
+ /* WARN: endp may have be freed after call to mgcp_endp_remove_conn */
talloc_free(conn);
}
diff --git a/src/libosmo-mgcp/mgcp_endp.c b/src/libosmo-mgcp/mgcp_endp.c
index c4f3653..ecb2845 100644
--- a/src/libosmo-mgcp/mgcp_endp.c
+++ b/src/libosmo-mgcp/mgcp_endp.c
@@ -666,3 +666,20 @@
OSMO_ASSERT(false);
}
}
+
+void mgcp_endp_add_conn(struct mgcp_endpoint *endp, struct mgcp_conn *conn)
+{
+ llist_add(&conn->entry, &endp->conns);
+}
+
+void mgcp_endp_remove_conn(struct mgcp_endpoint *endp, struct mgcp_conn *conn)
+{
+ /* Run endpoint cleanup action. By this we inform the endpoint about
+ * the removal of the connection and allow it to clean up its inner
+ * state accordingly */
+ if (endp->type->cleanup_cb)
+ endp->type->cleanup_cb(endp, conn);
+ llist_del(&conn->entry);
+ if (llist_empty(&endp->conns))
+ mgcp_endp_release(endp);
+}
diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c
index 75a4754..fa40f1f 100644
--- a/src/libosmo-mgcp/mgcp_network.c
+++ b/src/libosmo-mgcp/mgcp_network.c
@@ -1379,7 +1379,8 @@
* connections present when one connection is removed from the
* endpoint. */
llist_for_each_entry(conn_cleanup, &endp->conns, entry) {
- conn_cleanup->priv = NULL;
+ if (conn_cleanup->priv == conn)
+ conn_cleanup->priv = NULL;
}
}