]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix possible register memory leak
authorAnthony Minessale <anthony.minessale@gmail.com>
Tue, 6 May 2008 22:56:55 +0000 (22:56 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Tue, 6 May 2008 22:56:55 +0000 (22:56 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8281 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_presence.c

index 00bb5d7c2de0a74f9458f225fee0de2bd87a6a2e..6525d06ce028fd35141e2342a8a8eb57715ac798 100644 (file)
@@ -1899,6 +1899,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)
        silence_frame.flags = SFF_CNG;
 
        memset(&mod_sofia_globals, 0, sizeof(mod_sofia_globals));
+       mod_sofia_globals.destroy_private.destroy_nh = 1;
        mod_sofia_globals.pool = pool;
        switch_mutex_init(&mod_sofia_globals.mutex, SWITCH_MUTEX_NESTED, mod_sofia_globals.pool);
 
index f672730b4396eaf910f1ba1378831a74d920ad51..3d06027f3100d674038afefb1f94624bdd053d52 100644 (file)
@@ -100,6 +100,7 @@ struct sofia_private {
        char uuid[SWITCH_UUID_FORMATTED_LENGTH + 1];
        sofia_gateway_t *gateway;
        char gateway_name[512];
+       int destroy_nh;
 };
 
 #define set_param(ptr,val) if (ptr) {free(ptr) ; ptr = NULL;} if (val) {ptr = strdup(val);}
@@ -194,6 +195,7 @@ struct mod_sofia_globals {
        char guess_ip[80];
        switch_queue_t *presence_queue;
        switch_queue_t *mwi_queue;
+       struct sofia_private destroy_private;
 };
 extern struct mod_sofia_globals mod_sofia_globals;
 
index 5b9b3931e6b3686ab30987d236dc5c0f416eefda..2165d49b8dfac0fb25d677efbf733dcc1bc825dc 100644 (file)
@@ -194,7 +194,7 @@ void sofia_event_callback(nua_event_t event,
        switch_channel_t *channel = NULL;
        sofia_gateway_t *gateway = NULL;
 
-       if (sofia_private) {
+       if (sofia_private && sofia_private != &mod_sofia_globals.destroy_private) {
                if ((gateway = sofia_private->gateway)) {
                        if (switch_thread_rwlock_tryrdlock(gateway->profile->rwlock) != SWITCH_STATUS_SUCCESS) {
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Profile %s is locked\n", gateway->profile->name);
@@ -356,6 +356,11 @@ void sofia_event_callback(nua_event_t event,
 
   done:
 
+       if (sofia_private && sofia_private->destroy_nh) {
+               //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Destroy handle requested.\n");
+               nua_handle_destroy(nh);
+       }
+
        if (gateway) {
                sofia_reg_release_gateway(gateway);
        }
index 773c36d2995c9cb3b2a1cf05ae90727b7b9ff3e2..de08c1591b66a0842e7959337f283d0b9d88c9e7 100644 (file)
@@ -781,7 +781,8 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
                        exptime = tmp - switch_timestamp(NULL); 
                }
        }
-
+       
+       //if (!(nh = nua_handle_by_call_id(profile->nua, call_id))) {
        if (!(nh = (nua_handle_t *) switch_core_hash_find(profile->sub_hash, call_id))) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find handle for %s\n", call_id);
                return 0;
@@ -1045,7 +1046,7 @@ static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char *
        switch_snprintf(exp, sizeof(exp), "active;expires=%ld", (long) exptime); 
 
        nua_notify(nh,
-                          NUTAG_NEWSUB(1),
+                          //NUTAG_NEWSUB(1),
                           SIPTAG_SUBSCRIPTION_STATE_STR(exp),
                           SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR(ct), SIPTAG_PAYLOAD_STR(pl), TAG_END());
 
@@ -1090,6 +1091,7 @@ static int sofia_presence_mwi_callback(void *pArg, int argc, char **argv, char *
                return 0;
        }
        
+       //if (!(nh = nua_handle_by_call_id(profile->nua, call_id))) {
        if (!(nh = (nua_handle_t *) switch_core_hash_find(profile->sub_hash, call_id))) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find handle for %s\n", call_id);
                return 0;
@@ -1103,7 +1105,7 @@ static int sofia_presence_mwi_callback(void *pArg, int argc, char **argv, char *
        exp = switch_mprintf("active;expires=%ld", expire_sec);
 
        nua_notify(nh,
-                          NUTAG_NEWSUB(1),
+                          //NUTAG_NEWSUB(1),
                           SIPTAG_SUBSCRIPTION_STATE_STR(exp),
                           SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), SIPTAG_PAYLOAD_STR(body), TAG_END());
        
@@ -1146,6 +1148,7 @@ static int sofia_presence_mwi_callback2(void *pArg, int argc, char **argv, char
                                        SIPTAG_CONTACT_STR(profile->url),
                                        TAG_END());
        
+       nua_handle_bind(nh, &mod_sofia_globals.destroy_private);
        nua_notify(nh,
                           NUTAG_NEWSUB(1),
                           SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), SIPTAG_PAYLOAD_STR(body), TAG_END());
@@ -1347,6 +1350,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
                sent_reply++;
 
 #if 0
+               nua_handle_bind(nh, &mod_sofia_globals.destroy_private);
                nua_notify(nh, 
                                   NUTAG_NEWSUB(1),
                                   SIPTAG_SUBSCRIPTION_STATE_STR(sstr), SIPTAG_EVENT_STR(event),