diff --git a/third-party/pjproject/patches/0001-r5400-pjsip_tx_data_dec_ref.patch b/third-party/pjproject/patches/0001-r5400-pjsip_tx_data_dec_ref.patch index b5c11db..79bd111 100644 --- a/third-party/pjproject/patches/0001-r5400-pjsip_tx_data_dec_ref.patch +++ b/third-party/pjproject/patches/0001-r5400-pjsip_tx_data_dec_ref.patch @@ -1,14 +1,161 @@ -This patch fixes the issue in pjsip_tx_data_dec_ref() -when tx_data_destroy can be called more than once, -and checks if invalid value (e.g. NULL) is passed to. - +Index: pjlib/include/pj/lock.h +=================================================================== +--- a/pjlib/include/pj/lock.h (revision 5463) ++++ b/pjlib/include/pj/lock.h (working copy) +@@ -266,8 +266,10 @@ + * + * @return PJ_SUCCESS or the appropriate error code. + */ +-PJ_DECL(pj_status_t) pj_grp_lock_acquire( pj_grp_lock_t *grp_lock); ++#define pj_grp_lock_acquire(grp_lock) pj_grp_lock_acquire_dbg(grp_lock, __FILE__, __LINE__, __PRETTY_FUNCTION__) + ++PJ_DECL(pj_status_t) pj_grp_lock_acquire_dbg(pj_grp_lock_t *grp_lock, const char *file, int line, const char *func); ++ + /** + * Acquire lock on the specified group lock if it is available, otherwise + * return immediately wihout waiting. +@@ -276,8 +278,10 @@ + * + * @return PJ_SUCCESS or the appropriate error code. + */ +-PJ_DECL(pj_status_t) pj_grp_lock_tryacquire( pj_grp_lock_t *grp_lock); ++#define pj_grp_lock_tryacquire(grp_lock) pj_grp_lock_tryacquire_dbg(grp_lock, __FILE__, __LINE__, __PRETTY_FUNCTION__) + ++PJ_DECL(pj_status_t) pj_grp_lock_tryacquire_dbg(pj_grp_lock_t *grp_lock, const char *file, int line, const char *func); ++ + /** + * Release the previously held lock. This may cause the group lock + * to be destroyed if it is the last one to hold the reference counter. +@@ -287,8 +291,10 @@ + * + * @return PJ_SUCCESS or the appropriate error code. + */ +-PJ_DECL(pj_status_t) pj_grp_lock_release( pj_grp_lock_t *grp_lock); ++#define pj_grp_lock_release(grp_lock) pj_grp_lock_release_dbg(grp_lock, __FILE__, __LINE__, __PRETTY_FUNCTION__) + ++PJ_DECL(pj_status_t) pj_grp_lock_release_dbg(pj_grp_lock_t *grp_lock, const char *file, int line, const char *func); ++ + /** + * Add a destructor handler, to be called by the group lock when it is + * about to be destroyed. +Index: pjlib/src/pj/lock.c +=================================================================== +--- a/pjlib/src/pj/lock.c (revision 5463) ++++ b/pjlib/src/pj/lock.c (working copy) +@@ -473,19 +473,27 @@ + return grp_lock_destroy(grp_lock); + } + +-PJ_DEF(pj_status_t) pj_grp_lock_acquire( pj_grp_lock_t *grp_lock) ++PJ_DEF(pj_status_t) pj_grp_lock_acquire_dbg(pj_grp_lock_t *grp_lock, const char *file, int line, const char *func) + { +- return grp_lock_acquire(grp_lock); ++ pj_status_t status = grp_lock_acquire(grp_lock); ++ PJ_LOG(3,("grp_lock", "Acquired %p %s:%s(%d)", grp_lock, file, func, line)); ++ return status; + } + +-PJ_DEF(pj_status_t) pj_grp_lock_tryacquire( pj_grp_lock_t *grp_lock) ++PJ_DEF(pj_status_t) pj_grp_lock_tryacquire_dbg(pj_grp_lock_t *grp_lock, const char *file, int line, const char *func) + { +- return grp_lock_tryacquire(grp_lock); ++ pj_status_t status = grp_lock_tryacquire(grp_lock); ++ if (status == PJ_SUCCESS) { ++ PJ_LOG(3,("grp_lock", "Acquired %p %s:%s(%d)", grp_lock, file, func, line)); ++ } ++ return status; + } + +-PJ_DEF(pj_status_t) pj_grp_lock_release( pj_grp_lock_t *grp_lock) ++PJ_DEF(pj_status_t) pj_grp_lock_release_dbg(pj_grp_lock_t *grp_lock, const char *file, int line, const char *func) + { +- return grp_lock_release(grp_lock); ++ PJ_LOG(3,("grp_lock", "Released %p %s:%s(%d)", grp_lock, file, func, line)); ++ pj_status_t status = grp_lock_release(grp_lock); ++ return status; + } + + PJ_DEF(pj_status_t) pj_grp_lock_replace( pj_grp_lock_t *old_lock, +Index: pjsip/include/pjsip/sip_transport.h +=================================================================== +--- a/pjsip/include/pjsip/sip_transport.h (revision 5463) ++++ b/pjsip/include/pjsip/sip_transport.h (working copy) +@@ -652,8 +652,10 @@ + * + * @param tdata The transmit buffer. + */ +-PJ_DECL(void) pjsip_tx_data_add_ref( pjsip_tx_data *tdata ); ++#define pjsip_tx_data_add_ref(tdata) pjsip_tx_data_add_ref_dbg(tdata, __FILE__, __LINE__, __PRETTY_FUNCTION__) + ++PJ_DECL(void) pjsip_tx_data_add_ref_dbg(pjsip_tx_data *tdata, const char *file, int line, const char *func); ++ + /** + * Decrement reference counter of the transmit buffer. + * When the transmit buffer is no longer used, it will be destroyed and +@@ -664,8 +666,10 @@ + * status is non-zero. A status PJSIP_EBUFDESTROYED will be + * returned to inform that buffer is destroyed. + */ +-PJ_DECL(pj_status_t) pjsip_tx_data_dec_ref( pjsip_tx_data *tdata ); ++#define pjsip_tx_data_dec_ref(tdata) pjsip_tx_data_dec_ref_dbg(tdata, __FILE__, __LINE__, __PRETTY_FUNCTION__) + ++PJ_DECL(pj_status_t) pjsip_tx_data_dec_ref_dbg(pjsip_tx_data *tdata, const char *file, int line, const char *func); ++ + /** + * Print the SIP message to transmit data buffer's internal buffer. This + * may allocate memory for the buffer, if the buffer has not been allocated +Index: pjsip/src/pjsip/sip_transaction.c +=================================================================== +--- a/pjsip/src/pjsip/sip_transaction.c (revision 5463) ++++ b/pjsip/src/pjsip/sip_transaction.c (working copy) +@@ -1023,6 +1023,7 @@ + + pj_grp_lock_add_ref(tsx->grp_lock); + } ++ PJ_LOG(3,(tsx->obj_name, "Transaction %p has group lock %p", tsx, tsx->grp_lock)); + + status = pj_mutex_create_simple(pool, tsx->obj_name, &tsx->mutex_b); + if (status != PJ_SUCCESS) { +@@ -1039,7 +1040,7 @@ + { + pjsip_transaction *tsx = (pjsip_transaction*)arg; + +- PJ_LOG(5,(tsx->obj_name, "Transaction destroyed!")); ++ PJ_LOG(3,(tsx->obj_name, "Transaction destroyed! group lock %p", tsx->grp_lock)); + + pj_mutex_destroy(tsx->mutex_b); + pjsip_endpt_release_pool(tsx->endpt, tsx->pool); Index: pjsip/src/pjsip/sip_transport.c =================================================================== ---- a/pjsip/src/pjsip/sip_transport.c (revision 5399) -+++ b/pjsip/src/pjsip/sip_transport.c (revision 5400) -@@ -491,8 +491,13 @@ +--- a/pjsip/src/pjsip/sip_transport.c (revision 5463) ++++ b/pjsip/src/pjsip/sip_transport.c (working copy) +@@ -459,14 +459,17 @@ + /* + * Add reference to tx buffer. + */ +-PJ_DEF(void) pjsip_tx_data_add_ref( pjsip_tx_data *tdata ) ++PJ_DEF(void) pjsip_tx_data_add_ref_dbg(pjsip_tx_data *tdata, const char *file, int line, const char *func) + { +- pj_atomic_inc(tdata->ref_cnt); ++ pj_atomic_value_t ref_cnt; ++ ref_cnt = pj_atomic_inc_and_get(tdata->ref_cnt); ++ PJ_LOG(3,(tdata->obj_name, "Add ref tdata: %p ref_cnt: %d %s:%s(%d)", ++ tdata, (int)ref_cnt, file, func, line)); + } + + static void tx_data_destroy(pjsip_tx_data *tdata) + { +- PJ_LOG(5,(tdata->obj_name, "Destroying txdata %s", ++ PJ_LOG(3,(tdata->obj_name, "Destroying txdata %s", + pjsip_tx_data_get_info(tdata))); + pjsip_tpselector_dec_ref(&tdata->tp_sel); + #if defined(PJ_DEBUG) && PJ_DEBUG!=0 +@@ -489,13 +492,22 @@ + * Decrease transport data reference, destroy it when the reference count + * reaches zero. */ - PJ_DEF(pj_status_t) pjsip_tx_data_dec_ref( pjsip_tx_data *tdata ) +-PJ_DEF(pj_status_t) pjsip_tx_data_dec_ref( pjsip_tx_data *tdata ) ++PJ_DEF(pj_status_t) pjsip_tx_data_dec_ref_dbg(pjsip_tx_data *tdata, const char *file, int line, const char *func) { - pj_assert( pj_atomic_get(tdata->ref_cnt) > 0); - if (pj_atomic_dec_and_get(tdata->ref_cnt) <= 0) { @@ -19,6 +166,13 @@ Index: pjsip/src/pjsip/sip_transport.c + ref_cnt = pj_atomic_dec_and_get(tdata->ref_cnt); + pj_assert( ref_cnt >= 0); + if (ref_cnt == 0) { ++ PJ_LOG(3,(tdata->obj_name, "Destroying tdata: %p %s:%s(%d)", ++ tdata, file, func, line)); tx_data_destroy(tdata); return PJSIP_EBUFDESTROYED; } else { ++ PJ_LOG(3,(tdata->obj_name, "Dec ref tdata: %p ref_cnt: %d %s:%s(%d)", ++ tdata, (int)ref_cnt, file, func, line)); + return PJ_SUCCESS; + } + } diff --git a/third-party/pjproject/patches/config_site.h b/third-party/pjproject/patches/config_site.h index 0694f12..940169d 100644 --- a/third-party/pjproject/patches/config_site.h +++ b/third-party/pjproject/patches/config_site.h @@ -34,7 +34,7 @@ #define PJ_SCANNER_USE_BITWISE 0 #define PJ_OS_HAS_CHECK_STACK 0 -#define PJ_LOG_MAX_LEVEL 3 +#define PJ_LOG_MAX_LEVEL 5 #define PJ_ENABLE_EXTRA_CHECK 1 #define PJSIP_MAX_TSX_COUNT ((64*1024)-1) #define PJSIP_MAX_DIALOG_COUNT ((64*1024)-1)