]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Avoid deadlock, don't leak on duplicate gateway name, error on duplicate gateway...
authorMichael Jerris <mike@jerris.com>
Fri, 4 Apr 2008 18:53:24 +0000 (18:53 +0000)
committerMichael Jerris <mike@jerris.com>
Fri, 4 Apr 2008 18:53:24 +0000 (18:53 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8023 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_glue.c
src/mod/endpoints/mod_sofia/sofia_reg.c

index 5418131c15be78a7ced1839239a081966b22beff..e30b7d07ecb3981b2bfa259e2959623ad6ebba9f 100644 (file)
@@ -737,6 +737,14 @@ static void parse_gateways(sofia_profile_t *profile, switch_xml_t gateways_tag)
                        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 @@ static void parse_gateways(sofia_profile_t *profile, switch_xml_t gateways_tag)
                        }
                        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:
index e1e0689537df7e558291920ed61586368c15630e..1cc43f6365a1ba0f05be9e138165105fbea06a79 100644 (file)
@@ -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);
        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 @@ 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);
        }
 #endif
+
+ done:
        switch_mutex_unlock(mod_sofia_globals.hash_mutex);
 
        return profile;
index 2e22a31788c993ba5121bff8eb0ee9ab69602fa7..a84d7fa88a6bf9a9384784735cfc041b0839471b 100644 (file)
@@ -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);
        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 @@ 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);
 #endif
        }
+
+ done:
        switch_mutex_unlock(mod_sofia_globals.hash_mutex);
        return gateway;
 }