Ignore:
Timestamp:
Jun 26, 2014 10:39:35 AM (10 years ago)
Author:
ming
Message:

Fixed #1774: Unfreed transports upon stack shutdown/restart

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsip/sip_transport.c

    r4802 r4865  
    7878}; 
    7979 
     80/* Transport list item */ 
     81typedef struct transport 
     82{ 
     83    PJ_DECL_LIST_MEMBER(struct transport); 
     84    pjsip_transport *tp; 
     85} transport; 
     86 
    8087/* 
    8188 * Transport manager. 
     
    98105     */ 
    99106    pjsip_tx_data    tdata_list; 
     107     
     108    /* List of transports which are NOT stored in the hash table, so 
     109     * that it can be properly cleaned up when transport manager 
     110     * is destroyed. 
     111     */ 
     112    transport        tp_list; 
    100113}; 
    101114 
     
    10281041    hval = 0; 
    10291042    entry = pj_hash_get(mgr->table, &tp->key, key_len, &hval); 
    1030     if (entry != NULL) 
     1043    if (entry != NULL) { 
     1044        transport *tp_ref; 
     1045         
     1046        tp_ref = PJ_POOL_ZALLOC_T(((pjsip_transport *)entry)->pool, transport); 
     1047         
     1048        /* 
     1049         * Add transport to the list before removing it from the hash table. 
     1050         * See ticket #1774 for more details. 
     1051         */ 
     1052        tp_ref->tp = (pjsip_transport *)entry; 
     1053        pj_list_push_back(&mgr->tp_list, tp_ref); 
    10311054        pj_hash_set(NULL, mgr->table, &tp->key, key_len, hval, NULL); 
     1055    } 
    10321056 
    10331057    /* Register new entry */ 
     
    10751099    hval = 0; 
    10761100    entry = pj_hash_get(mgr->table, &tp->key, key_len, &hval); 
    1077     if (entry == (void*)tp) 
     1101    if (entry == (void*)tp) { 
    10781102        pj_hash_set(NULL, mgr->table, &tp->key, key_len, hval, NULL); 
     1103    } else { 
     1104        /* If not found in hash table, remove from the tranport list. */ 
     1105        transport *tp_iter = mgr->tp_list.next; 
     1106        while (tp_iter != &mgr->tp_list) { 
     1107            if (tp_iter->tp == tp) { 
     1108                pj_list_erase(tp_iter); 
     1109                break; 
     1110            } 
     1111            tp_iter = tp_iter->next; 
     1112        } 
     1113    } 
    10791114 
    10801115    pj_lock_release(mgr->lock); 
     
    12591294    pj_list_init(&mgr->factory_list); 
    12601295    pj_list_init(&mgr->tdata_list); 
     1296    pj_list_init(&mgr->tp_list); 
    12611297 
    12621298    mgr->table = pj_hash_create(pool, PJSIP_TPMGR_HTABLE_SIZE); 
     
    15271563 
    15281564    /* 
    1529      * Destroy all transports. 
     1565     * Destroy all transports in the hash table. 
    15301566     */ 
    15311567    itr = pj_hash_first(mgr->table, &itr_val); 
     
    15431579    } 
    15441580 
     1581    /* 
     1582     * Destroy transports in the list. 
     1583     */ 
     1584    if (!pj_list_empty(&mgr->tp_list)) { 
     1585        transport *tp_iter = mgr->tp_list.next; 
     1586        while (tp_iter != &mgr->tp_list) { 
     1587            transport *next = tp_iter->next; 
     1588            destroy_transport(mgr, tp_iter->tp); 
     1589            tp_iter = next; 
     1590        } 
     1591    } 
     1592     
    15451593    /* 
    15461594     * Destroy all factories/listeners. 
Note: See TracChangeset for help on using the changeset viewer.