From a2740a96c8afdfee370fdfb0d27b238014c6057a Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Wed, 3 Sep 2008 18:29:19 +0000 Subject: [PATCH] Wed Sep 3 13:55:22 EDT 2008 Pekka Pessi * nua: using HAVE_MEMLEAK_LOG Logging nua_handle_ref() and nua_handle_unref(). git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9420 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- libs/sofia-sip/.update | 2 +- .../libsofia-sip-ua/nua/nua_common.c | 45 ++++++++++++++++++- .../sofia-sip/libsofia-sip-ua/nua/nua_stack.h | 45 ++++++------------- 3 files changed, 58 insertions(+), 34 deletions(-) diff --git a/libs/sofia-sip/.update b/libs/sofia-sip/.update index 55bf715ebb..5c67f4b6f2 100644 --- a/libs/sofia-sip/.update +++ b/libs/sofia-sip/.update @@ -1 +1 @@ -Wed Sep 3 14:27:37 EDT 2008 +Wed Sep 3 14:29:03 EDT 2008 diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/nua_common.c b/libs/sofia-sip/libsofia-sip-ua/nua/nua_common.c index df9643871f..19e2655e0b 100644 --- a/libs/sofia-sip/libsofia-sip-ua/nua/nua_common.c +++ b/libs/sofia-sip/libsofia-sip-ua/nua/nua_common.c @@ -163,8 +163,47 @@ static void nh_destructor(void *arg) SU_DEBUG_0(("nh_destructor(%p)\n", (void *)nh)); } -#undef nua_handle_ref -#undef nua_handle_unref +#if HAVE_MEMLEAK_LOG + +nua_handle_t * +_nua_handle_ref_by(nua_handle_t *nh, + char const *file, unsigned line, + char const *function) +{ + if (nh) + SU_DEBUG_0(("%p - nua_handle_ref() => "MOD_ZU" by %s:%u: %s()\n", + nh, su_home_refcount((su_home_t *)nh) + 1, file, line, by)); + return (nua_handle_t *)su_home_ref((su_home_t *)nh); +} + +int +_nua_handle_unref_by(nua_handle_t *nh, + char const *file, unsigned line, + char const *function) +{ + if (nh) { + size_t refcount = su_home_refcount((su_home_t *)nh) - 1; + int freed = su_home_unref((su_home_t *)nh); + if (freed) refcount = 0; + SU_DEBUG_0(("%p - nua_handle_unref() => "MOD_ZU" by %s:%u: %s()\n", + nh, refcount, file, line, by)); + return freed; + } + + return 0; +} + +nua_handle_t *nua_handle_ref(nua_handle_t *nh) +{ + return _nua_handle_ref_by(nh, "", 0, "") +} + +int nua_handle_unref(nua_handle_t *nh) +{ + return _nua_handle_unref_by(nh, "", 0, "") +} + +#else /** Make a new reference to handle. * @@ -198,6 +237,8 @@ int nua_handle_unref(nua_handle_t *nh) return su_home_unref(nh->nh_home); } +#endif + /** Generate an instance identifier. */ char const *nua_generate_instance_identifier(su_home_t *home) { diff --git a/libs/sofia-sip/libsofia-sip-ua/nua/nua_stack.h b/libs/sofia-sip/libsofia-sip-ua/nua/nua_stack.h index d5144ca2db..81a0163609 100644 --- a/libs/sofia-sip/libsofia-sip-ua/nua/nua_stack.h +++ b/libs/sofia-sip/libsofia-sip-ua/nua/nua_stack.h @@ -103,37 +103,6 @@ typedef struct register_usage nua_registration_t; TAG_IF((include) && (soa) && soa_is_remote_chat_active(soa) >= 0, \ SOATAG_ACTIVE_CHAT(soa_is_remote_chat_active(soa))) -#if HAVE_NUA_HANDLE_DEBUG - -#define nua_handle_ref(nh) nua_handle_ref_by((nh), __func__) -#define nua_handle_unref(nh) nua_handle_unref_by((nh), __func__) - -su_inline nua_handle_t *nua_handle_ref_by(nua_handle_t *nh, - char const *by) -{ - if (nh) - SU_DEBUG_0(("nua_handle_ref(%p) => "MOD_ZU" by %s\n", nh, - su_home_refcount((su_home_t *)nh) + 1, - by)); - return (nua_handle_t *)su_home_ref((su_home_t *)nh); -} - -su_inline int nua_handle_unref_by(nua_handle_t *nh, char const *by) -{ - if (nh) { - size_t refcount = su_home_refcount((su_home_t *)nh) - 1; - int freed = su_home_unref((su_home_t *)nh); - if (freed) refcount = 0; - SU_DEBUG_0(("nua_handle_unref(%p) => "MOD_ZU" by %s\n", - nh, refcount, by)); - return freed; - } - - return 0; -} - -#endif - /** @internal @brief NUA handle. * */ @@ -277,6 +246,20 @@ struct nua_s { #define __func__ "nua" #endif +#if HAVE_MEMLEAK_LOG + +#define nua_handle_ref(nh) \ + _nua_handle_ref_by((nh), __FILE__, __LINE__, __func__) +#define nua_handle_unref(nh) \ + _nua_handle_unref_by((nh), __FILE__, __LINE__, __func__) + +nua_handle_t *_nua_handle_ref_by( + nua_handle_t *nh, char const *file, unsigned line, char const *by); +int _nua_handle_unref_by( + nua_handle_t *nh, char const *file, unsigned line, char const *by); + +#endif + su_inline nua_t *nua_stack_ref(nua_t *nua) { return (nua_t *)su_home_ref(nua->nua_home);