From fc9a8ef971b55f59d4f7ffaed6a7ea4752922552 Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Wed, 24 Apr 2024 15:45:37 +0200 Subject: [PATCH 1/2] Release some references created by remote publishers. --- src/plugins/janus_videoroom.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/plugins/janus_videoroom.c b/src/plugins/janus_videoroom.c index 5ff99541d6..4ae1f305d7 100644 --- a/src/plugins/janus_videoroom.c +++ b/src/plugins/janus_videoroom.c @@ -2713,6 +2713,8 @@ static void janus_videoroom_publisher_dereference_nodebug(janus_videoroom_publis janus_refcount_decrease_nodebug(&p->ref); } +static void janus_videoroom_session_destroy(janus_videoroom_session *session); + static void janus_videoroom_publisher_destroy(janus_videoroom_publisher *p) { if(p && g_atomic_int_compare_and_exchange(&p->destroyed, 0, 1)) { janus_mutex_lock(&p->streams_mutex); @@ -2750,6 +2752,9 @@ static void janus_videoroom_publisher_destroy(janus_videoroom_publisher *p) { } janus_mutex_unlock(&p->rtp_forwarders_mutex); janus_mutex_unlock(&p->streams_mutex); + /* Release dummy session of the forwarder */ + if(p->session && p->session->handle == NULL) + janus_videoroom_session_destroy(p->session); janus_refcount_decrease(&p->ref); } } @@ -2799,7 +2804,8 @@ static void janus_videoroom_session_destroy(janus_videoroom_session *session) { static void janus_videoroom_session_free(const janus_refcount *session_ref) { janus_videoroom_session *session = janus_refcount_containerof(session_ref, janus_videoroom_session, ref); /* Remove the reference to the core plugin session */ - janus_refcount_decrease(&session->handle->ref); + if (session->handle) + janus_refcount_decrease(&session->handle->ref); /* This session can be destroyed, free all the resources */ janus_mutex_destroy(&session->mutex); g_free(session); @@ -7291,6 +7297,7 @@ static json_t *janus_videoroom_process_synchronous_request(janus_videoroom_sessi json_object_set_new(response, "id", string_ids ? json_string(publisher->user_id_str) : json_integer(publisher->user_id)); json_object_set_new(response, "remote_id", json_string(remote_id)); janus_refcount_decrease(&publisher->ref); /* This is just to handle the request for now */ + janus_refcount_decrease(&videoroom->ref); goto prepare_response; } else if(!strcasecmp(request_text, "unpublish_remotely")) { /* Configure a local publisher to stop restreaming to a remote VideoRomm instance */ @@ -13795,7 +13802,7 @@ static void *janus_videoroom_remote_publisher_thread(void *user_data) { } g_list_free(subscribers); /* Free streams */ - g_list_free(publisher->streams); + g_list_free_full(publisher->streams, (GDestroyNotify)(janus_videoroom_publisher_stream_unref)); publisher->streams = NULL; g_hash_table_remove_all(publisher->streams_byid); g_hash_table_remove_all(publisher->streams_bymid); From 3167a3627682e26b2b0ea0c8e319f61a01b22596 Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Thu, 4 Jul 2024 21:50:11 +0200 Subject: [PATCH 2/2] Update check for dummy forwarder session. --- src/plugins/janus_videoroom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/janus_videoroom.c b/src/plugins/janus_videoroom.c index 4ae1f305d7..ded372d799 100644 --- a/src/plugins/janus_videoroom.c +++ b/src/plugins/janus_videoroom.c @@ -2753,7 +2753,7 @@ static void janus_videoroom_publisher_destroy(janus_videoroom_publisher *p) { janus_mutex_unlock(&p->rtp_forwarders_mutex); janus_mutex_unlock(&p->streams_mutex); /* Release dummy session of the forwarder */ - if(p->session && p->session->handle == NULL) + if(p->remote && p->session) janus_videoroom_session_destroy(p->session); janus_refcount_decrease(&p->ref); }