Ignore:
Timestamp:
Dec 26, 2006 3:56:29 AM (18 years ago)
Author:
bennylp
Message:

Fixed ticket #42: duplicate hash entry when TCP/TLS connection is created while previous one is shutting down

File:
1 edited

Legend:

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

    r861 r866  
    639639{ 
    640640    int key_len; 
     641    pj_uint32_t hval; 
     642    void *entry; 
    641643 
    642644    /* Init. */ 
     
    647649 
    648650    /*  
    649      * Register to hash table. 
     651     * Register to hash table (see Trac ticket #42). 
    650652     */ 
    651653    key_len = sizeof(tp->key.type) + tp->addr_len; 
    652654    pj_lock_acquire(mgr->lock); 
    653     pj_hash_set(tp->pool, mgr->table, &tp->key, key_len, 0, tp); 
     655 
     656    /* If entry already occupied, unregister previous entry */ 
     657    hval = 0; 
     658    entry = pj_hash_get(mgr->table, &tp->key, key_len, &hval); 
     659    if (entry != NULL) 
     660        pj_hash_set(NULL, mgr->table, &tp->key, key_len, hval, NULL); 
     661 
     662    /* Register new entry */ 
     663    pj_hash_set(tp->pool, mgr->table, &tp->key, key_len, hval, tp); 
     664 
    654665    pj_lock_release(mgr->lock); 
    655666 
     
    668679{ 
    669680    int key_len; 
     681    pj_uint32_t hval; 
     682    void *entry; 
    670683 
    671684    TRACE_((THIS_FILE, "Transport %s is being destroyed", tp->obj_name)); 
     
    684697 
    685698    /* 
    686      * Unregister from hash table. 
     699     * Unregister from hash table (see Trac ticket #42). 
    687700     */ 
    688701    key_len = sizeof(tp->key.type) + tp->addr_len; 
    689     pj_assert(pj_hash_get(mgr->table, &tp->key, key_len, NULL) != NULL); 
    690     pj_hash_set(tp->pool, mgr->table, &tp->key, key_len, 0, NULL); 
     702    hval = 0; 
     703    entry = pj_hash_get(mgr->table, &tp->key, key_len, &hval); 
     704    if (entry == (void*)tp) 
     705        pj_hash_set(NULL, mgr->table, &tp->key, key_len, hval, NULL); 
    691706 
    692707    pj_lock_release(mgr->lock); 
Note: See TracChangeset for help on using the changeset viewer.