From f989eef2dc706b4ea751053d9c841b4e6ccfbfd7 Mon Sep 17 00:00:00 2001 From: Evgeniy Baranov Date: Mon, 25 Jan 2021 01:47:57 +0300 Subject: [PATCH] fix race condition in audiobridge plugin changeroom request --- plugins/janus_audiobridge.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/plugins/janus_audiobridge.c b/plugins/janus_audiobridge.c index dc15c7ed05..d922024266 100644 --- a/plugins/janus_audiobridge.c +++ b/plugins/janus_audiobridge.c @@ -5734,13 +5734,6 @@ static void *janus_audiobridge_handler(void *data) { } } else if(!strcasecmp(request_text, "changeroom")) { /* The participant wants to leave the current room and join another one without reconnecting (e.g., a sidebar) */ - janus_audiobridge_participant *participant = (janus_audiobridge_participant *)session->participant; - if(participant == NULL || participant->room == NULL) { - JANUS_LOG(LOG_ERR, "Can't change room (not in a room in the first place)\n"); - error_code = JANUS_AUDIOBRIDGE_ERROR_NOT_JOINED; - g_snprintf(error_cause, 512, "Can't change room (not in a room in the first place)"); - goto error; - } JANUS_VALIDATE_JSON_OBJECT(root, join_parameters, error_code, error_cause, TRUE, JANUS_AUDIOBRIDGE_ERROR_MISSING_ELEMENT, JANUS_AUDIOBRIDGE_ERROR_INVALID_ELEMENT); @@ -5768,6 +5761,14 @@ static void *janus_audiobridge_handler(void *data) { room_id_str = (char *)json_string_value(room); } janus_mutex_lock(&rooms_mutex); + janus_audiobridge_participant *participant = (janus_audiobridge_participant *)session->participant; + if(participant == NULL || participant->room == NULL) { + janus_mutex_unlock(&rooms_mutex); + JANUS_LOG(LOG_ERR, "Can't change room (not in a room in the first place)\n"); + error_code = JANUS_AUDIOBRIDGE_ERROR_NOT_JOINED; + g_snprintf(error_cause, 512, "Can't change room (not in a room in the first place)"); + goto error; + } /* Is this the same room we're in? */ if(participant->room && ((!string_ids && participant->room->room_id == room_id) || (string_ids && participant->room->room_id_str && !strcmp(participant->room->room_id_str, room_id_str)))) {