[Freeswitch-svn] [commit] r8023 - freeswitch/trunk/src/mod/endpoints/mod_sofia
Freeswitch SVN
mikej at freeswitch.org
Fri Apr 4 14:53:25 EDT 2008
Author: mikej
Date: Fri Apr 4 14:53:24 2008
New Revision: 8023
Modified:
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
Log:
Avoid deadlock, don't leak on duplicate gateway name, error on duplicate gateway name
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c Fri Apr 4 14:53:24 2008
@@ -737,6 +737,14 @@
name = "anonymous";
}
+ switch_mutex_lock(mod_sofia_globals.hash_mutex);
+ if ((gp = switch_core_hash_find(mod_sofia_globals.gateway_hash, name))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignoring duplicate gateway '%s'\n", name);
+ switch_mutex_unlock(mod_sofia_globals.hash_mutex);
+ goto skip;
+ }
+ switch_mutex_unlock(mod_sofia_globals.hash_mutex);
+
if ((gateway = switch_core_alloc(profile->pool, sizeof(*gateway)))) {
char *register_str = "true", *scheme = "Digest",
*realm = NULL,
@@ -893,14 +901,9 @@
}
gateway->freq -= 2;
- if ((gp = sofia_reg_find_gateway(gateway->name))) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignoring duplicate gateway '%s'\n", gateway->name);
- sofia_reg_release_gateway(gp);
- } else {
- gateway->next = profile->gateways;
- profile->gateways = gateway;
- sofia_reg_add_gateway(gateway->name, gateway);
- }
+ gateway->next = profile->gateways;
+ profile->gateways = gateway;
+ sofia_reg_add_gateway(gateway->name, gateway);
}
skip:
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Fri Apr 4 14:53:24 2008
@@ -2285,7 +2285,8 @@
switch_mutex_lock(mod_sofia_globals.hash_mutex);
if ((profile = (sofia_profile_t *) switch_core_hash_find(mod_sofia_globals.profile_hash, key))) {
if (!(profile->pflags & PFLAG_RUNNING)) {
- return NULL;
+ profile = NULL;
+ goto done;
}
if (switch_thread_rwlock_tryrdlock(profile->rwlock) != SWITCH_STATUS_SUCCESS) {
#ifdef SOFIA_DEBUG_RWLOCKS
@@ -2303,6 +2304,8 @@
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_ERROR, "XXXXXXXXXXXXXX LOCK %s\n", profile->name);
}
#endif
+
+ done:
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
return profile;
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c Fri Apr 4 14:53:24 2008
@@ -1149,7 +1149,8 @@
switch_mutex_lock(mod_sofia_globals.hash_mutex);
if ((gateway = (sofia_gateway_t *) switch_core_hash_find(mod_sofia_globals.gateway_hash, key))) {
if (!(gateway->profile->pflags & PFLAG_RUNNING)) {
- return NULL;
+ gateway = NULL;
+ goto done;
}
if (switch_thread_rwlock_tryrdlock(gateway->profile->rwlock) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "Profile %s is locked\n", gateway->profile->name);
@@ -1161,6 +1162,8 @@
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_ERROR, "XXXXXXXXXXXXXX GW LOCK %s\n", gateway->profile->name);
#endif
}
+
+ done:
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
return gateway;
}
More information about the Freeswitch-svn
mailing list