Changeset 6142 for pjproject


Ignore:
Timestamp:
Jan 29, 2020 4:05:51 AM (5 years ago)
Author:
ming
Message:

Fixed #2264: Potential deadlock between pjsua lock and sip transport's lock

Location:
pjproject/trunk/pjsip
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/include/pjsip-ua/sip_regc.h

    r6035 r6142  
    210210                                     pj_uint32_t expires); 
    211211 
     212 
     213/** 
     214 * Increment busy counter temporarily, to prevent client registration 
     215 * structure from being destroyed. 
     216 * 
     217 * @param regc      The client registration structure. 
     218 */ 
     219PJ_DECL(void) pjsip_regc_add_ref( pjsip_regc *regc ); 
     220 
     221 
     222/** 
     223 * Decrement temporary busy counter. After this function 
     224 * is called, client registration structure may have been destroyed 
     225 * if there's a pending destroy. 
     226 * 
     227 * @param regc      The client registration structure. 
     228 * 
     229 * @return          PJ_SUCCESS on success. PJ_EGONE if the registration 
     230 *                  structure has been destroyed inside the function. 
     231 */ 
     232PJ_DECL(pj_status_t) pjsip_regc_dec_ref( pjsip_regc *regc ); 
     233 
     234 
    212235/** 
    213236 * Set callback to be called when the registration received a final response. 
  • pjproject/trunk/pjsip/src/pjsip-ua/sip_reg.c

    r6134 r6142  
    398398} 
    399399 
     400PJ_DEF(void) pjsip_regc_add_ref( pjsip_regc *regc ) 
     401{ 
     402    pj_assert(regc); 
     403    pj_atomic_inc(regc->busy_ctr); 
     404} 
     405 
     406PJ_DEF(pj_status_t) pjsip_regc_dec_ref( pjsip_regc *regc ) 
     407{ 
     408    pj_assert(regc); 
     409    if (pj_atomic_dec_and_get(regc->busy_ctr)==0 && regc->_delete_flag) { 
     410        pjsip_regc_destroy(regc); 
     411        return PJ_EGONE; 
     412    } 
     413     
     414    return PJ_SUCCESS; 
     415} 
     416 
    400417PJ_DEF(pj_status_t) pjsip_regc_set_credentials( pjsip_regc *regc, 
    401418                                                int count, 
     
    788805     * in pjsip_regc_send() or in the callback 
    789806     */ 
    790     pj_atomic_inc(regc->busy_ctr); 
     807    pjsip_regc_add_ref(regc); 
    791808 
    792809    entry->id = 0; 
     
    804821 
    805822    /* Delete the record if user destroy regc during the callback. */ 
    806     if (pj_atomic_dec_and_get(regc->busy_ctr)==0 && regc->_delete_flag) { 
    807         pjsip_regc_destroy(regc); 
    808     } 
     823    pjsip_regc_dec_ref(regc); 
    809824} 
    810825 
     
    10681083    pj_bool_t update_contact = PJ_FALSE; 
    10691084 
    1070     pj_atomic_inc(regc->busy_ctr); 
     1085    pjsip_regc_add_ref(regc); 
    10711086    pj_lock_acquire(regc->lock); 
    10721087 
     
    13681383 
    13691384    /* Delete the record if user destroy regc during the callback. */ 
    1370     if (pj_atomic_dec_and_get(regc->busy_ctr)==0 && regc->_delete_flag) { 
    1371         pjsip_regc_destroy(regc); 
    1372     } 
     1385    pjsip_regc_dec_ref(regc); 
    13731386} 
    13741387 
     
    13801393    pj_uint32_t cseq; 
    13811394 
    1382     pj_atomic_inc(regc->busy_ctr); 
     1395    pjsip_regc_add_ref(regc); 
    13831396    pj_lock_acquire(regc->lock); 
    13841397 
     
    14811494 
    14821495    /* Delete the record if user destroy regc during the callback. */ 
    1483     if (pj_atomic_dec_and_get(regc->busy_ctr)==0 && regc->_delete_flag) { 
    1484         pjsip_regc_destroy(regc); 
    1485     } 
     1496    pjsip_regc_dec_ref(regc); 
    14861497 
    14871498    return status; 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_acc.c

    r6141 r6142  
    27792779        } 
    27802780 
     2781        /* Increment ref counter and release PJSUA lock here, to avoid 
     2782         * deadlock while making sure that regc won't be destroyed. 
     2783         */ 
     2784        pjsip_regc_add_ref(pjsua_var.acc[acc_id].regc); 
     2785        PJSUA_UNLOCK(); 
     2786         
    27812787        //pjsua_process_msg_data(tdata, NULL); 
    27822788        status = pjsip_regc_send( pjsua_var.acc[acc_id].regc, tdata ); 
     2789         
     2790        PJSUA_LOCK(); 
     2791        if (pjsip_regc_dec_ref(pjsua_var.acc[acc_id].regc) == PJ_EGONE) { 
     2792            /* regc has been deleted. */ 
     2793            goto on_return; 
     2794        } 
    27832795    } 
    27842796 
Note: See TracChangeset for help on using the changeset viewer.