Avoid deadlock, don't leak on duplicate gateway name, error on duplicate gateway name
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8023 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
4c9b1270ca
commit
86cc41d646
|
@ -737,6 +737,14 @@ static void parse_gateways(sofia_profile_t *profile, switch_xml_t gateways_tag)
|
||||||
name = "anonymous";
|
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)))) {
|
if ((gateway = switch_core_alloc(profile->pool, sizeof(*gateway)))) {
|
||||||
char *register_str = "true", *scheme = "Digest",
|
char *register_str = "true", *scheme = "Digest",
|
||||||
*realm = NULL,
|
*realm = NULL,
|
||||||
|
@ -893,14 +901,9 @@ static void parse_gateways(sofia_profile_t *profile, switch_xml_t gateways_tag)
|
||||||
}
|
}
|
||||||
gateway->freq -= 2;
|
gateway->freq -= 2;
|
||||||
|
|
||||||
if ((gp = sofia_reg_find_gateway(gateway->name))) {
|
gateway->next = profile->gateways;
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignoring duplicate gateway '%s'\n", gateway->name);
|
profile->gateways = gateway;
|
||||||
sofia_reg_release_gateway(gp);
|
sofia_reg_add_gateway(gateway->name, gateway);
|
||||||
} else {
|
|
||||||
gateway->next = profile->gateways;
|
|
||||||
profile->gateways = gateway;
|
|
||||||
sofia_reg_add_gateway(gateway->name, gateway);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
skip:
|
skip:
|
||||||
|
|
|
@ -2285,7 +2285,8 @@ sofia_profile_t *sofia_glue_find_profile__(const char *file, const char *func, i
|
||||||
switch_mutex_lock(mod_sofia_globals.hash_mutex);
|
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 = (sofia_profile_t *) switch_core_hash_find(mod_sofia_globals.profile_hash, key))) {
|
||||||
if (!(profile->pflags & PFLAG_RUNNING)) {
|
if (!(profile->pflags & PFLAG_RUNNING)) {
|
||||||
return NULL;
|
profile = NULL;
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
if (switch_thread_rwlock_tryrdlock(profile->rwlock) != SWITCH_STATUS_SUCCESS) {
|
if (switch_thread_rwlock_tryrdlock(profile->rwlock) != SWITCH_STATUS_SUCCESS) {
|
||||||
#ifdef SOFIA_DEBUG_RWLOCKS
|
#ifdef SOFIA_DEBUG_RWLOCKS
|
||||||
|
@ -2303,6 +2304,8 @@ sofia_profile_t *sofia_glue_find_profile__(const char *file, const char *func, i
|
||||||
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_ERROR, "XXXXXXXXXXXXXX LOCK %s\n", profile->name);
|
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_ERROR, "XXXXXXXXXXXXXX LOCK %s\n", profile->name);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
done:
|
||||||
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
|
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
|
||||||
|
|
||||||
return profile;
|
return profile;
|
||||||
|
|
|
@ -1149,7 +1149,8 @@ sofia_gateway_t *sofia_reg_find_gateway__(const char *file, const char *func, in
|
||||||
switch_mutex_lock(mod_sofia_globals.hash_mutex);
|
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 = (sofia_gateway_t *) switch_core_hash_find(mod_sofia_globals.gateway_hash, key))) {
|
||||||
if (!(gateway->profile->pflags & PFLAG_RUNNING)) {
|
if (!(gateway->profile->pflags & PFLAG_RUNNING)) {
|
||||||
return NULL;
|
gateway = NULL;
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
if (switch_thread_rwlock_tryrdlock(gateway->profile->rwlock) != SWITCH_STATUS_SUCCESS) {
|
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);
|
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 @@ sofia_gateway_t *sofia_reg_find_gateway__(const char *file, const char *func, in
|
||||||
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_ERROR, "XXXXXXXXXXXXXX GW LOCK %s\n", gateway->profile->name);
|
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_ERROR, "XXXXXXXXXXXXXX GW LOCK %s\n", gateway->profile->name);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
|
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
|
||||||
return gateway;
|
return gateway;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue