From 4e567a28a209a2037d88af51c04b75cdec1214cc Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 15 Sep 2010 18:57:54 -0500 Subject: [PATCH] fix logic in app flags --- src/switch_channel.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/switch_channel.c b/src/switch_channel.c index e3d77d7239..ba5560129b 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -1291,19 +1291,24 @@ SWITCH_DECLARE(int) switch_channel_test_private_flag(switch_channel_t *channel, SWITCH_DECLARE(void) switch_channel_set_app_flag_key(const char *key, switch_channel_t *channel, uint32_t flags) { uint32_t *flagp = NULL; - + switch_byte_t new = 0; + switch_assert(channel != NULL); switch_mutex_lock(channel->flag_mutex); - - if (channel->app_flag_hash) { - flagp = switch_core_hash_find(channel->app_flag_hash, key); - } else { + + if (!channel->app_flag_hash) { switch_core_hash_init(&channel->app_flag_hash, switch_core_session_get_pool(channel->session)); + new++; + } + + if (new || !(flagp = switch_core_hash_find(channel->app_flag_hash, key))) { flagp = switch_core_session_alloc(channel->session, sizeof(uint32_t)); switch_core_hash_insert(channel->app_flag_hash, key, flagp); } - if (flagp) *flagp |= flags; + switch_assert(flagp); + *flagp |= flags; + switch_mutex_unlock(channel->flag_mutex); }