[Core] switch_channel_clear_state_handler(), switch_channel_get_state_handler(): Coverity 1546120 Data race condition

* [Core] switch_channel_clear_state_handler: Coverity 1546120 Data race condition

* [Core] Fix race in switch_channel_get_state_handler()
This commit is contained in:
Andrey Volk 2024-11-13 22:56:15 +03:00 committed by GitHub
parent ee7c7dea60
commit 4658192547
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 5 deletions

View File

@ -3072,12 +3072,12 @@ SWITCH_DECLARE(const switch_state_handler_table_t *) switch_channel_get_state_ha
switch_assert(channel != NULL);
if (index >= SWITCH_MAX_STATE_HANDLERS || index > channel->state_handler_index) {
return NULL;
switch_mutex_lock(channel->state_mutex);
if (index < SWITCH_MAX_STATE_HANDLERS && index <= channel->state_handler_index) {
h = channel->state_handlers[index];
}
switch_mutex_lock(channel->state_mutex);
h = channel->state_handlers[index];
switch_mutex_unlock(channel->state_mutex);
return h;
@ -3085,12 +3085,13 @@ SWITCH_DECLARE(const switch_state_handler_table_t *) switch_channel_get_state_ha
SWITCH_DECLARE(void) switch_channel_clear_state_handler(switch_channel_t *channel, const switch_state_handler_table_t *state_handler)
{
int index, i = channel->state_handler_index;
int index, i;
const switch_state_handler_table_t *new_handlers[SWITCH_MAX_STATE_HANDLERS] = { 0 };
switch_assert(channel != NULL);
switch_mutex_lock(channel->state_mutex);
i = channel->state_handler_index;
channel->state_handler_index = 0;
if (state_handler) {