From 5346a22930ad12474a0804396cd0b7ba7ab86704 Mon Sep 17 00:00:00 2001 From: Alessandro Toppi Date: Wed, 24 Apr 2024 11:29:03 +0200 Subject: [PATCH] videoroom: keep subscriber reference for the whole message handler (fixes #3354) (#3355) --- src/plugins/janus_videoroom.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/plugins/janus_videoroom.c b/src/plugins/janus_videoroom.c index c23e357b8c..c273a47e1c 100644 --- a/src/plugins/janus_videoroom.c +++ b/src/plugins/janus_videoroom.c @@ -8962,7 +8962,7 @@ static void *janus_videoroom_handler(void *data) { error_code = 0; root = NULL; if(msg->message == NULL) { - if(session->participant_type == janus_videoroom_p_type_subscriber) { + if(subscriber != NULL) { janus_refcount_decrease(&subscriber->ref); } JANUS_LOG(LOG_ERR, "No message??\n"); @@ -8976,7 +8976,7 @@ static void *janus_videoroom_handler(void *data) { error_code, error_cause, TRUE, JANUS_VIDEOROOM_ERROR_MISSING_ELEMENT, JANUS_VIDEOROOM_ERROR_INVALID_ELEMENT); if(error_code != 0) { - if(session->participant_type == janus_videoroom_p_type_subscriber) { + if(subscriber != NULL) { janus_refcount_decrease(&subscriber->ref); } goto error; @@ -11419,6 +11419,7 @@ static void *janus_videoroom_handler(void *data) { g_atomic_int_set(&subscriber->pending_restart, 1); janus_mutex_unlock(&subscriber->streams_mutex); JANUS_LOG(LOG_VERB, "Post-poning new ICE restart offer, waiting for previous answer\n"); + janus_refcount_decrease(&subscriber->ref); janus_videoroom_message_free(msg); continue; } @@ -11432,6 +11433,7 @@ static void *janus_videoroom_handler(void *data) { JANUS_LOG(LOG_VERB, " >> Pushing event: %d (took %"SCNu64" us)\n", res, janus_get_monotonic_time()-start); json_decref(event); json_decref(jsep); + janus_refcount_decrease(&subscriber->ref); /* Done */ janus_videoroom_message_free(msg); continue; @@ -11760,6 +11762,7 @@ static void *janus_videoroom_handler(void *data) { janus_mutex_unlock(&stream_ps->subscribers_mutex); janus_refcount_decrease(&stream_ps->ref); } + /* Subscribe to the new one */ janus_mutex_lock(&ps->subscribers_mutex); stream->publisher_streams = g_slist_append(stream->publisher_streams, ps); @@ -11930,7 +11933,6 @@ static void *janus_videoroom_handler(void *data) { janus_refcount_decrease(&subscriber->ref); goto error; } - janus_refcount_decrease(&subscriber->ref); } /* Prepare JSON event */ @@ -11969,9 +11971,11 @@ static void *janus_videoroom_handler(void *data) { JANUS_LOG(LOG_VERB, " >> %d (%s)\n", ret, janus_get_api_error(ret)); json_decref(event); /* Take note of the fact we got our answer */ - janus_videoroom_subscriber *subscriber = (janus_videoroom_subscriber *)session->participant; - if(subscriber == NULL) { + if(session->participant == NULL) { /* Shouldn't happen? */ + if(subscriber != NULL) + janus_refcount_decrease(&subscriber->ref); + janus_videoroom_message_free(msg); continue; } janus_mutex_lock(&subscriber->streams_mutex); @@ -12027,6 +12031,7 @@ static void *janus_videoroom_handler(void *data) { g_atomic_int_set(&subscriber->answered, 1); janus_mutex_unlock(&subscriber->streams_mutex); } + janus_refcount_decrease(&subscriber->ref); janus_videoroom_message_free(msg); continue; } else { @@ -12604,6 +12609,8 @@ static void *janus_videoroom_handler(void *data) { if(participant != NULL) janus_refcount_decrease(&participant->ref); } + if(subscriber != NULL) + janus_refcount_decrease(&subscriber->ref); janus_videoroom_message_free(msg); continue;