mod_limit: Avoiding segfault

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14403 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Mathieu Rene 2009-07-28 20:43:45 +00:00
parent 91726e3a76
commit 14fda9d617
1 changed files with 16 additions and 9 deletions

View File

@ -966,20 +966,27 @@ static void limit_hash_release(switch_core_session_t *session, const char *realm
switch_channel_t *channel = switch_core_session_get_channel(session);
limit_hash_private_t *pvt = switch_channel_get_private(channel, "limit_hash");
limit_hash_item_t *item = NULL;
char *hashkey = switch_core_session_sprintf(session, "%s_%s", realm, id);
char *hashkey = NULL;
if (!pvt || !pvt->hash) {
return;
}
hashkey = switch_core_session_sprintf(session, "%s_%s", realm, id);
switch_mutex_lock(globals.limit_hash_mutex);
item = (limit_hash_item_t*)switch_core_hash_find(pvt->hash, hashkey);
item->total_usage--;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Usage for %s is now %d\n", (const char*)hashkey, item->total_usage);
if ((item = (limit_hash_item_t*)switch_core_hash_find(pvt->hash, hashkey))) {
item->total_usage--;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Usage for %s is now %d\n", (const char*)hashkey, item->total_usage);
switch_core_hash_delete(pvt->hash, hashkey);
switch_core_hash_delete(pvt->hash, hashkey);
if (item->total_usage == 0) {
/* Noone is using this item anymore */
switch_core_hash_delete(globals.limit_hash, (const char*)hashkey);
free(item);
if (item->total_usage == 0) {
/* Noone is using this item anymore */
switch_core_hash_delete(globals.limit_hash, (const char*)hashkey);
free(item);
}
}
switch_mutex_unlock(globals.limit_hash_mutex);