[asterisk-commits] murf: branch murf/bug11210 r91232 - in /team/murf/bug11210: apps/ channels/ f...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Dec 5 14:25:53 CST 2007


Author: murf
Date: Wed Dec  5 14:25:52 2007
New Revision: 91232

URL: http://svn.digium.com/view/asterisk?view=rev&rev=91232
Log:
A bunch of fixes, and an event reporter for the object system. I modified astobj2 to have it pump out to a file, all the of 'events' (eg. object allocated, refcounts modified, object destruction, etc). You sort this to get a per-object history from creation to death, of all refcount manips. Hopefully this will help me understand what's going on. It's stupid and ugly, but it does the job. I had to add some definitions to every file that uses astobj2, a total of 7.

Modified:
    team/murf/bug11210/apps/app_queue.c
    team/murf/bug11210/channels/chan_iax2.c
    team/murf/bug11210/channels/chan_sip.c
    team/murf/bug11210/funcs/func_dialgroup.c
    team/murf/bug11210/include/asterisk/astobj2.h
    team/murf/bug11210/main/astobj2.c
    team/murf/bug11210/main/config.c
    team/murf/bug11210/main/manager.c
    team/murf/bug11210/utils/hashtest2.c

Modified: team/murf/bug11210/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug11210/apps/app_queue.c?view=diff&rev=91232&r1=91231&r2=91232
==============================================================================
--- team/murf/bug11210/apps/app_queue.c (original)
+++ team/murf/bug11210/apps/app_queue.c Wed Dec  5 14:25:52 2007
@@ -88,6 +88,25 @@
 #include "asterisk/astobj2.h"
 #include "asterisk/strings.h"
 #include "asterisk/global_datastores.h"
+
+#define ao2_ref(arg1, arg2) ao2_ref_debug((arg1), (arg2), "app_queue",  __FILE__, __LINE__, __PRETTY_FUNCTION__)
+int ao2_ref_debug(void *o, int delta, char *tag, char *file, int line, const char *funcname);
+#define ao2_link(arg1,arg2)  ao2_link_debug((arg1), (arg2), "app_queue", __FILE__, __LINE__, __PRETTY_FUNCTION__)
+int ao2_link_debug(struct ao2_container *c, void *o2, char *tag, char *file, int line, const char *funcname);
+#define ao2_unlink(arg1, arg2) ao2_unlink_debug((arg1), (arg2), "app_queue",  __FILE__, __LINE__, __PRETTY_FUNCTION__)
+void *ao2_unlink_debug(struct ao2_container *c, void *obj, char *tag, char *file, int line, const char *funcname);
+#define ao2_alloc(arg1,arg2) ao2_alloc_debug((arg1), (arg2), "app_queue",  __FILE__, __LINE__, __PRETTY_FUNCTION__)
+void *ao2_alloc_debug(const size_t data_size, ao2_destructor_fn destructor_fn, char *tag, char *file, int line, const char *funcname);
+#define ao2_container_alloc(arg1,arg2,arg3) ao2_container_alloc_debug((arg1), (arg2), (arg3), "app_queue",  __FILE__, __LINE__, __PRETTY_FUNCTION__)
+struct ao2_container *ao2_container_alloc_debug(const uint n_buckets,
+                                                                                                ao2_hash_fn *hash_fn, ao2_callback_fn *cmp_fn,
+                                                                                                char *tag, char *file, int line, const char *funcname);
+#define ao2_callback(arg1,arg2,arg3,arg4) ao2_callback_debug((arg1), (arg2), (arg3), (arg4), "app_queue",  __FILE__, __LINE__, __PRETTY_FUNCTION__)
+void *ao2_callback_debug(struct ao2_container *c, enum search_flags flags,
+                                                 ao2_callback_fn *cb_fn, void *arg, char *tag,
+                                                 char *file, int line, const char *funcname);
+#define ao2_find(arg1,arg2,arg3) ao2_find_debug((arg1), (arg2), (arg3), "app_queue",  __FILE__, __LINE__, __PRETTY_FUNCTION__)
+void *ao2_find_debug(struct ao2_container *c, void *arg, enum search_flags flags, char *tag, char *file, int line, const char *funcname);
 
 enum {
 	QUEUE_STRATEGY_RINGALL = 0,

Modified: team/murf/bug11210/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug11210/channels/chan_iax2.c?view=diff&rev=91232&r1=91231&r2=91232
==============================================================================
--- team/murf/bug11210/channels/chan_iax2.c (original)
+++ team/murf/bug11210/channels/chan_iax2.c Wed Dec  5 14:25:52 2007
@@ -87,6 +87,24 @@
 #include "asterisk/linkedlists.h"
 #include "asterisk/event.h"
 #include "asterisk/astobj2.h"
+#define ao2_ref(arg1,arg2)  ao2_ref_debug((arg1), (arg2), "IAX", __FILE__, __LINE__, __PRETTY_FUNCTION__)
+int ao2_ref_debug(void *o, int delta, char *tag, char *file, int line, const char *funcname);
+#define ao2_link(arg1,arg2)  ao2_link_debug((arg1), (arg2), "IAX", __FILE__, __LINE__, __PRETTY_FUNCTION__)
+int ao2_link_debug(struct ao2_container *c, void *o2, char *tag, char *file, int line, const char *funcname);
+#define ao2_unlink(arg1, arg2) ao2_unlink_debug((arg1), (arg2), "IAX",  __FILE__, __LINE__, __PRETTY_FUNCTION__)
+void *ao2_unlink_debug(struct ao2_container *c, void *obj, char *tag, char *file, int line, const char *funcname);
+#define ao2_alloc(arg1,arg2) ao2_alloc_debug((arg1), (arg2), "IAX",  __FILE__, __LINE__, __PRETTY_FUNCTION__)
+void *ao2_alloc_debug(const size_t data_size, ao2_destructor_fn destructor_fn, char *tag, char *file, int line, const char *funcname);
+#define ao2_container_alloc(arg1,arg2,arg3) ao2_container_alloc_debug((arg1), (arg2), (arg3), "IAX",  __FILE__, __LINE__, __PRETTY_FUNCTION__)
+struct ao2_container *ao2_container_alloc_debug(const uint n_buckets,
+                                                                                                ao2_hash_fn *hash_fn, ao2_callback_fn *cmp_fn,
+                                                                                                char *tag, char *file, int line, const char *funcname);
+#define ao2_callback(arg1,arg2,arg3,arg4) ao2_callback_debug((arg1), (arg2), (arg3), (arg4), "IAX",  __FILE__, __LINE__, __PRETTY_FUNCTION__)
+void *ao2_callback_debug(struct ao2_container *c, enum search_flags flags,
+                                                 ao2_callback_fn *cb_fn, void *arg, char *tag,
+                                                 char *file, int line, const char *funcname);
+#define ao2_find(arg1,arg2,arg3) ao2_find_debug((arg1), (arg2), (arg3), "IAX",  __FILE__, __LINE__, __PRETTY_FUNCTION__)
+void *ao2_find_debug(struct ao2_container *c, void *arg, enum search_flags flags, char *tag, char *file, int line, const char *funcname);
 
 #include "iax2.h"
 #include "iax2-parser.h"

Modified: team/murf/bug11210/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug11210/channels/chan_sip.c?view=diff&rev=91232&r1=91231&r2=91232
==============================================================================
--- team/murf/bug11210/channels/chan_sip.c (original)
+++ team/murf/bug11210/channels/chan_sip.c Wed Dec  5 14:25:52 2007
@@ -120,6 +120,7 @@
 #include "asterisk/utils.h"
 #include "asterisk/file.h"
 #include "asterisk/astobj.h"
+#define  REF_DEBUG 1
 #include "asterisk/astobj2.h"
 #include "asterisk/dnsmgr.h"
 #include "asterisk/devicestate.h"
@@ -652,7 +653,7 @@
 /* Object counters */
 static int suserobjs = 0;                /*!< Static users */
 static int ruserobjs = 0;                /*!< Realtime users */
-static int speerobjs = 0;                /*!< Statis peers */
+static int speerobjs = 0;                /*!< Static peers */
 static int rpeerobjs = 0;                /*!< Realtime peers */
 static int apeerobjs = 0;                /*!< Autocreated peer objects */
 static int regobjs = 0;                  /*!< Registry objects */
@@ -1202,15 +1203,19 @@
  * functions so we keep track of the refcounts.
  * To simplify the code, we allow a NULL to be passed to dialog_unref().
  */
-static struct sip_pvt *dialog_ref(struct sip_pvt *p)
-{
-	ao2_ref(p,1);
+static struct sip_pvt *dialog_ref(struct sip_pvt *p, char *tag)
+{
+	if (p)
+		ao2_ref(p,1,tag);
+	else
+		ast_log(LOG_ERROR,"Attempt to Ref a null pointer\n");
 	return p;
 }
 
-static struct sip_pvt *dialog_unref(struct sip_pvt *p)
-{
-	ao2_ref(p,-1);
+static struct sip_pvt *dialog_unref(struct sip_pvt *p, char *tag)
+{
+	if (p)
+		ao2_ref(p,-1, tag);
 	return NULL;
 }
 
@@ -1518,8 +1523,8 @@
  */
 static int dialog_cmp_cb(void *obj, void *arg, int flags)
 {
-	struct sip_registry *pvt = obj, *pvt2 = arg;
-
+	struct sip_pvt *pvt = obj, *pvt2 = arg;
+	ast_log(LOG_NOTICE,"obj %s == obj %s ? %d\n", pvt->callid, pvt2->callid, !strcasecmp(pvt->callid, pvt2->callid) ? CMP_MATCH : 0);
 	return !strcasecmp(pvt->callid, pvt2->callid) ? CMP_MATCH : 0;
 }
 
@@ -1670,7 +1675,7 @@
 static void sip_cancel_destroy(struct sip_pvt *p);
 static struct sip_pvt *sip_destroy(struct sip_pvt *p);
 static void *dialog_unlink_all(struct sip_pvt *dialog, int lockowner, int lockdialoglist);
-static void *registry_unref(struct sip_registry *reg);
+static void *registry_unref(struct sip_registry *reg, char *tag);
 static void __sip_destroy(struct sip_pvt *p);
 static void __sip_ack(struct sip_pvt *p, int seqno, int resp, int sipmethod);
 static void __sip_pretend_ack(struct sip_pvt *p);
@@ -2025,30 +2030,33 @@
  * By handling them this way, we don't have to declare the
  * destructor on each call, which removes the chance of errors.
  */
-static void unref_peer(struct sip_peer *peer)
-{
-	int rc = ao2_ref(peer,-1);
+static void *unref_peer(struct sip_peer *peer, char *tag)
+{
+	int rc = ao2_ref(peer,-1,tag);
 	ast_log(LOG_NOTICE,"Unref peer %s prev refcount=%d\n", peer->name, rc);
-}
-
-static void unref_user(struct sip_user *user)
-{
-	int rc = ao2_ref(user,-1);
+	return NULL;
+}
+
+static void *unref_user(struct sip_user *user, char *tag)
+{
+	int rc = ao2_ref(user,-1, tag);
 	ast_log(LOG_NOTICE,"Unref user %s prev refcount=%d\n", user->name, rc);
+	return NULL;
 }
 
 static void *dialog_unlink_all(struct sip_pvt *dialog, int lockowner, int lockdialoglist)
 {
-	struct sip_pvt *x;
-	int rc = ao2_ref(dialog,0);
+	int rc = ao2_ref(dialog,0, "");
 	ast_log(LOG_NOTICE,"Unlink dialog %s prev refcount=%d\n", dialog->callid, rc);
 	/* Remove link from peer to subscription of MWI */
 	if (dialog->relatedpeer && dialog->relatedpeer->mwipvt) 
-		dialog->relatedpeer->mwipvt = dialog_unref(dialog->relatedpeer->mwipvt);
+		dialog->relatedpeer->mwipvt = dialog_unref(dialog->relatedpeer->mwipvt, "delete ->relatedpeer->mwipvt");
+	rc = ao2_ref(dialog,0,"");
+	ast_log(LOG_NOTICE,"Unlink dialog %s prev refcount=%d\n", dialog->callid, rc);
 	if (dialog->registry) {
 		if (dialog->registry->call == dialog)
 			dialog->registry->call = NULL;
-		dialog->registry = registry_unref(dialog->registry);
+		dialog->registry = registry_unref(dialog->registry, "delete dialog->registry");
 	}
 	/* Unlink us from the owner if we have one */
 	if (dialog->owner) {
@@ -2059,11 +2067,21 @@
 		if (lockowner)
 			ast_channel_unlock(dialog->owner);
 	}
-	x = ao2_find(dialogs, dialog, OBJ_POINTER|OBJ_UNLINK);
+	rc = ao2_ref(dialog,0,"");
+	ast_log(LOG_NOTICE,"Unlink dialog %s prev refcount=%d\n", dialog->callid, rc);
+	ao2_unlink(dialogs, dialog, "unlinking dialog via ao2_unlink");
+	/* x = ao2_find(dialogs, dialog, OBJ_POINTER|OBJ_UNLINK);
+	if (!x)
+		ast_log(LOG_NOTICE,"find/unlink returns NULL\n");
+	else
+	dialog_unref(x,"remove result of ao2_find");
+	*/
+	rc = ao2_ref(dialog,0,"");
+	ast_log(LOG_NOTICE,"Unlink dialog %s prev refcount=%d\n", dialog->callid, rc);
 	return NULL;
 }
 
-static void *registry_unref(struct sip_registry *reg)
+static void *registry_unref(struct sip_registry *reg, char *tag)
 {
 	ast_debug(3, "SIP Registry %s: refcount now %d\n", reg->hostname, reg->refcount - 1);
 	ASTOBJ_UNREF(reg, sip_registry_destroy);
@@ -2071,7 +2089,7 @@
 }
 
 /*! \brief Add object reference to SIP registry */
-static struct sip_registry *registry_addref(struct sip_registry *reg)
+static struct sip_registry *registry_addref(struct sip_registry *reg, char *tag)
 {
 	ast_debug(3, "SIP Registry %s: refcount now %d\n", reg->hostname, reg->refcount + 1);
 	return ASTOBJ_REF(reg);	/* Add pointer to registry in packet */
@@ -2555,7 +2573,7 @@
 	pkt->seqno = seqno;
 	pkt->is_resp = resp;
 	pkt->is_fatal = fatal;
-	pkt->owner = dialog_ref(p);
+	pkt->owner = dialog_ref(p,"__sip_reliable_xmit: setting pkt->owner");
 	pkt->next = p->packets;
 	p->packets = pkt;
 	pkt->timer_t1 = p->timer_t1;	/* Set SIP timer T1 */
@@ -2611,7 +2629,7 @@
 
 	if (p->subscribed == MWI_NOTIFICATION)
 		if (p->relatedpeer)
-			unref_peer(p->relatedpeer);	/* Remove link to peer. If it's realtime, make sure it's gone from memory) */
+			p->relatedpeer = unref_peer(p->relatedpeer,"__sip_autodestruct: unref peer p->relatedpeer");	/* Remove link to peer. If it's realtime, make sure it's gone from memory) */
 
 	/* Reset schedule ID */
 	p->autokillid = -1;
@@ -2619,19 +2637,19 @@
 	if (p->owner) {
 		ast_log(LOG_WARNING, "Autodestruct on dialog '%s' with owner in place (Method: %s)\n", p->callid, sip_methods[p->method].text);
 		ast_queue_hangup(p->owner);
-		dialog_unref(p);
+		dialog_unref(p,"unref dialog when owner is set");
 	} else if (p->refer) {
 		ast_debug(3, "Finally hanging up channel after transfer: %s\n", p->callid);
 		transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, 1);
 		append_history(p, "ReferBYE", "Sending BYE on transferer call leg %s", p->callid);
 		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
-		dialog_unref(p);
+		dialog_unref(p,"unref dialog when refer is set");
 	} else {
 		append_history(p, "AutoDestroy", "%s", p->callid);
 		ast_debug(3, "Auto destroying SIP dialog '%s'\n", p->callid);
 		ast_log(LOG_NOTICE,"AutoDestroy dialog %s\n", p->callid);
 		dialog_unlink_all(p, TRUE, TRUE); /* once it's unlinked and unrefd everywhere, it'll be freed automagically */
-		
+		dialog_unref(p,"unref dialog-- no other matching conditions"); /* theoretically, this should be the last ref to this dialog */
 		/* sip_destroy(p); */		/* Go ahead and destroy dialog. All attempts to recover is done */
 		/* sip_destroy also absorbs the reference */
 	}
@@ -2651,7 +2669,7 @@
 	sip_cancel_destroy(p);
 	if (p->do_history)
 		append_history(p, "SchedDestroy", "%d ms", ms);
-	p->autokillid = ast_sched_add(sched, ms, __sip_autodestruct, dialog_ref(p));
+	p->autokillid = ast_sched_add(sched, ms, __sip_autodestruct, dialog_ref(p,"sip_scheddestroy: setting ref as passing into ast_sched_add"));
 }
 
 /*! \brief Cancel destruction of SIP dialog.
@@ -2664,7 +2682,7 @@
 		ast_sched_del(sched, p->autokillid);
 		append_history(p, "CancelDestroy", "");
 		p->autokillid = -1;
-		dialog_unref(p);
+		dialog_unref(p,"dialog unrefd because autokillid is > -1");
 	}
 }
 
@@ -2700,7 +2718,7 @@
 				cur->retransid = -1;
 			}
 			UNLINK(cur, p->packets, prev);
-			dialog_unref(cur->owner);
+			cur->owner = dialog_unref(cur->owner,"dialog ptd to by sip_pkt->owner is to be freed");
 			ast_free(cur);
 			break;
 		}
@@ -3128,7 +3146,7 @@
 static void sip_destroy_peer(struct sip_peer *peer)
 {
 	ast_debug(3, "Destroying SIP peer %s\n", peer->name);
-
+	ast_log(LOG_NOTICE,"Destroying SIP peer %s\n", peer->name);
 	if (peer->outboundproxy)
 		ast_free(peer->outboundproxy);
 	peer->outboundproxy = NULL;
@@ -3137,13 +3155,15 @@
 	if (peer->call) {
 		ast_log(LOG_NOTICE,"Calling Sip_Destroy() from peer for %s....\n", peer->call->callid);
 		dialog_unlink_all(peer->call, TRUE, TRUE);
+		peer->call = dialog_unref(peer->call,"peer->call is being unset");
 		/* peer->call = sip_destroy(peer->call); */
 	}
 	
 
 	if (peer->mwipvt) {	/* We have an active subscription, delete it */
 		ast_log(LOG_NOTICE,"Calling Sip_Destroy() from mwipvt for %s....\n", peer->mwipvt->callid);
-		peer->mwipvt = dialog_unlink_all(peer->mwipvt, TRUE, TRUE);
+		dialog_unlink_all(peer->mwipvt, TRUE, TRUE);
+		peer->mwipvt = dialog_unref(peer->mwipvt, "unreffing peer->mwipvt");
 		/* peer->mwipvt = sip_destroy(peer->mwipvt); */
 	}
 	
@@ -3352,8 +3372,8 @@
 			peer->expire = ast_sched_replace(peer->expire, sched, 
 				global_rtautoclear * 1000, expire_register, (void *) peer);
 		}
-		ao2_link(peers, peer);
-		ao2_link(peers_by_ip, peer);
+		ao2_link(peers, peer, "link peer into peers table");
+		ao2_link(peers_by_ip, peer, "link peer into peers_by_ip table");
 	} else {
 		peer->is_realtime = 1;
 	}
@@ -3396,12 +3416,12 @@
 	if (peer)
 	{
 		ast_copy_string(tmp_peer.name, peer, sizeof(tmp_peer.name));
-		p = ao2_find(peers, &tmp_peer, OBJ_POINTER);
+		p = ao2_find(peers, &tmp_peer, OBJ_POINTER,"ao2_find in peers table");
 	} else if (sin) { /* search by addr? */
 		tmp_peer.addr.sin_addr.s_addr = sin->sin_addr.s_addr;
 		tmp_peer.addr.sin_port = sin->sin_port;
 		ast_log(LOG_NOTICE,"Searching for peer %s by IP addr/port = %d/%d\n", peer, sin->sin_addr.s_addr, sin->sin_port);
-		p = ao2_find(peers_by_ip, &tmp_peer, OBJ_POINTER); /* WAS:  p = ASTOBJ_CONTAINER_FIND_FULL(&peerl, sin, name, sip_addr_hashfunc, 1, sip_addrcmp); */
+		p = ao2_find(peers_by_ip, &tmp_peer, OBJ_POINTER,"ao2_find in peers_by_ip table"); /* WAS:  p = ASTOBJ_CONTAINER_FIND_FULL(&peerl, sin, name, sip_addr_hashfunc, 1, sip_addrcmp); */
 	}
 	
 
@@ -3414,7 +3434,7 @@
 		ast_log(LOG_NOTICE,"Did not find peer %s / addr=%d port=%d\n", peer, sin->sin_addr.s_addr, sin->sin_port);
 
 	if (p) {
-		rc = ao2_ref(p,0);
+		rc = ao2_ref(p,0,"");
 		ast_log(LOG_NOTICE,"FOUND peer %s refcount = %d\n", peer, rc);
 	}
 	return p;
@@ -3430,6 +3450,7 @@
 static void sip_destroy_user(struct sip_user *user)
 {
 	ast_debug(3, "Destroying user object from memory: %s\n", user->name);
+	ast_log(LOG_NOTICE,"Destroying SIP user %s\n", user->name);
 	ast_free_ha(user->ha);
 	if (user->chanvars) {
 		ast_variables_destroy(user->chanvars);
@@ -3474,7 +3495,7 @@
 	if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS)) {
 		ast_set_flag(&user->flags[1], SIP_PAGE2_RTCACHEFRIENDS);
 		suserobjs++;
-		ao2_link(users, user);
+		ao2_link(users, user, "link user into users table");
 	} else {
 		/* Move counter from s to r... */
 		suserobjs--;
@@ -3495,7 +3516,7 @@
 	struct sip_user *u;
 
 	ast_copy_string(tmp.name, name, sizeof(tmp.name));
-	u = ao2_find(users, &tmp, OBJ_POINTER);
+	u = ao2_find(users, &tmp, OBJ_POINTER, "ao2_find in users table");
 
 	if (!u && realtime)
 		u = realtime_user(name);
@@ -3672,7 +3693,7 @@
 
 	if (peer) {
 		int res = create_addr_from_peer(dialog, peer);
-		unref_peer(peer);
+		unref_peer(peer,"create_addr: unref peer from find_peer hashtab lookup");
 		return res;
 	}
 
@@ -3732,7 +3753,7 @@
 		}
 	}
 	sip_pvt_unlock(p);
-	dialog_unref(p);
+	dialog_unref(p,"unreffing arg passed into auto_conget -- is this right?");
 	return 0;
 }
 
@@ -3820,7 +3841,7 @@
 	
 		/* Initialize auto-congest time */
 		p->initid = ast_sched_replace(p->initid, sched, SIP_TRANS_TIMEOUT, 
-			auto_congest, dialog_ref(p));
+									  auto_congest, dialog_ref(p, "sip_call: bumping refcount as calling ast_sched_replace"));
 	}
 
 	return res;
@@ -3832,14 +3853,16 @@
 {
 	/* Really delete */
 	ast_debug(3, "Destroying registry entry for %s@%s\n", reg->username, reg->hostname);
+	ast_log(LOG_NOTICE,"Destroying SIP registry entry  %s@%s\n", reg->username, reg->hostname);
 
 	if (reg->call) {
 		/* Clear registry before destroying to ensure
 		   we don't get reentered trying to grab the registry lock */
-		reg->call->registry = NULL;
+		reg->call->registry = registry_unref(reg->call->registry, "destroy reg->call->registry");
 		ast_debug(3, "Destroying active SIP dialog for registry %s@%s\n", reg->username, reg->hostname);
 		ast_log(LOG_NOTICE,"Calling Sip_Destroy() from registry for %s....\n", reg->call->callid);
-		reg->call = dialog_unlink_all(reg->call, TRUE, TRUE);
+		dialog_unlink_all(reg->call, TRUE, TRUE);
+		reg->call = dialog_unref(reg->call,"unref reg->call");
 		/* reg->call = sip_destroy(reg->call); */
 	}
 	if (reg->expire > -1)
@@ -3858,7 +3881,7 @@
 {
 	struct sip_pkt *cp;
 
-	ast_log(LOG_NOTICE,"Destroying the empty shell of dialog %s\n", p->callid);
+	ast_log(LOG_NOTICE,"======Destroying the empty shell of dialog %s=====\n", p->callid);
 	if (sip_debug_test_pvt(p))
 		ast_verbose("Really destroying SIP dialog '%s' Method: %s\n", p->callid, sip_methods[p->method].text);
 
@@ -3911,7 +3934,7 @@
 		p->packets = p->packets->next;
 		if (cp->retransid > -1)
 			ast_sched_del(sched, cp->retransid);
-		dialog_unref(cp->owner);
+		dialog_unref(cp->owner,"free cp->owner dialog before freeing the pkt");
 		ast_free(cp);
 	}
 	if (p->chanvars) {
@@ -4005,9 +4028,9 @@
 			if (*inuse >= *call_limit) {
 				ast_log(LOG_ERROR, "Call %s %s '%s' rejected due to usage limit of %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit);
 				if (u)
-					unref_user(u);
+					unref_user(u,"update_call_counter: unref user u call limit exceeded");
 				else
-					unref_peer(p);
+					unref_peer(p, "update_call_counter: unref peer p, call limit exceeded");
 				return -1; 
 			}
 		}
@@ -4037,9 +4060,9 @@
 	}
 	if (p) {
 		ast_device_state_changed("SIP/%s", p->name);
-		unref_peer(p);
+		unref_peer(p,"update_call_counter: unref_peer from call counter");
 	} else /* u must be set */
-		unref_user(u);
+		unref_user(u,"update_call_counter: unref_user from call counter");
 	return 0;
 }
 
@@ -4254,7 +4277,7 @@
 		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
 		ast_clear_flag(&p->flags[0], SIP_DEFER_BYE_ON_TRANSFER);	/* Really hang up next time */
 		p->needdestroy = 0;
-		p->owner->tech_pvt = dialog_unref(p->owner->tech_pvt);
+		p->owner->tech_pvt = dialog_unref(p->owner->tech_pvt, "unref p->owner->tech_pvt");
 		p->owner = NULL;  /* Owner will be gone after we return, so take it away */
 		return 0;
 	}
@@ -4296,7 +4319,7 @@
 		ast_dsp_free(p->vad);
 
 	p->owner = NULL;
-	ast->tech_pvt = dialog_unref(ast->tech_pvt);
+	ast->tech_pvt = dialog_unref(ast->tech_pvt, "unref ast->tech_pvt");
 
 	ast_module_unref(ast_module_info->self);
 	/* Do not destroy this pvt until we have timeout or
@@ -4848,7 +4871,7 @@
 	tmp->rawwriteformat = fmt;
 	tmp->readformat = fmt;
 	tmp->rawreadformat = fmt;
-	tmp->tech_pvt = dialog_ref(i);
+	tmp->tech_pvt = dialog_ref(i, "sip_new: set chan->tech_pvt to i");
 
 	tmp->callgroup = i->callgroup;
 	tmp->pickupgroup = i->pickupgroup;
@@ -5208,7 +5231,7 @@
 	int rc;
 
 	ast_log(LOG_NOTICE,"allocating PVT for %s\n", callid);
-	if (!(p = ao2_alloc(sizeof(*p), sip_destroy_fn)))
+	if (!(p = ao2_alloc(sizeof(*p), sip_destroy_fn, "allocate a dialog(pvt) struct")))
 		return NULL;
 
 	if (ast_string_field_init(p, 512)) {
@@ -5329,14 +5352,14 @@
 	/* Add to active dialog list */
 
 	ast_log(LOG_NOTICE,"***About to Search for dialog %s\n", p->callid);
-	p2 = ao2_find(dialogs, p, OBJ_POINTER);
+	p2 = ao2_find(dialogs, p, OBJ_POINTER, "ao2_find in dialogs");
 	if (p2) {
 		ast_log(LOG_NOTICE, "ABOUT TO LINK %s, but it is already in the dialog table!\n", p2->callid);
-		ao2_ref(p2,-1);
+		ao2_ref(p2,-1,"ao2_find success for a check");
 	}
 	
-	ao2_link(dialogs, p);
-	rc = ao2_ref(p, 0);
+	ao2_link(dialogs, p, "link pvt into dialogs table");
+	rc = ao2_ref(p, 0,"");
 	
 	ast_debug(1, "Allocating new SIP dialog for %s - %s (%s)\n", callid ? callid : "(No Call-ID)", sip_methods[intended_method].text, p->rtp ? "With RTP" : "No RTP");
 	return p;
@@ -5397,13 +5420,13 @@
 		int rc;
 		ast_string_field_set(&tmp_dialog, callid, callid);
 	
-		sip_pvt_ptr = ao2_find(dialogs, &tmp_dialog, OBJ_POINTER);
+		sip_pvt_ptr = ao2_find(dialogs, &tmp_dialog, OBJ_POINTER, "ao2_find in dialogs");
 		if (sip_pvt_ptr) {
-			rc = ao2_ref(sip_pvt_ptr,0);
+			rc = ao2_ref(sip_pvt_ptr,0,"");
 			ast_log(LOG_NOTICE,"Found CALL dialog %s, refcount = %d\n", tmp_dialog.callid, rc);
 			if (!(!pedanticsipchecking || !tag || ast_strlen_zero(sip_pvt_ptr->theirtag) || !strcmp(sip_pvt_ptr->theirtag, tag)))
 			{
-				ao2_ref(sip_pvt_ptr,-1); /* basically, if the extra pedanticssipchecking constraints don't pan out,
+				ao2_ref(sip_pvt_ptr,-1,"pedantic failure, pointer erase"); /* basically, if the extra pedanticssipchecking constraints don't pan out,
 											the the match is defeated. There should be no other entry that matches
 											the callid */
 				sip_pvt_ptr = 0;
@@ -5412,11 +5435,11 @@
 			if (pedanticsipchecking && sip_pvt_ptr  && req->method != SIP_RESPONSE) {	/* SIP Request */
 				if (sip_pvt_ptr->tag[0] == '\0' && totag[0]) {
 					/* We have no to tag, but they have. Wrong dialog */
-					ao2_ref(sip_pvt_ptr,-1);
+					ao2_ref(sip_pvt_ptr,-1,"pedantic failure, pointer erased 2");
 					sip_pvt_ptr = NULL;
 				} else if (totag[0]) {			/* Both have tags, compare them */
 					if (strcmp(totag, sip_pvt_ptr->tag)) {
-						ao2_ref(sip_pvt_ptr,-1);
+						ao2_ref(sip_pvt_ptr,-1, "pedantic totag failure, pointer erased 3");
 						sip_pvt_ptr = NULL;		/* This is not our packet */
 					}
 				}
@@ -5447,7 +5470,7 @@
 		} else {
 			/* Ok, time to create a new SIP dialog object, a pvt */
 			if ((p = sip_alloc(callid, sin, 1, intended_method)))  {
-				int rc = ao2_ref(p,0);
+				int rc = ao2_ref(p,0,"");
 				ast_log(LOG_NOTICE,"Couldn't find call %s, so CREATED dialog, refcount = %d\n",
 						callid, rc);
 				/* Ok, we've created a dialog, let's go and process it */
@@ -5557,7 +5580,7 @@
 	reg->callid_valid = FALSE;
 	reg->ocseq = INITIAL_CSEQ;
 	ASTOBJ_CONTAINER_LINK(&regl, reg); /* Add the new registry entry to the list */
-	registry_unref(reg);	/* release the reference given by ASTOBJ_INIT. The container has another reference */
+	registry_unref(reg,"unref the reg pointer");	/* release the reference given by ASTOBJ_INIT. The container has another reference */
 	return 0;
 }
 
@@ -8380,7 +8403,7 @@
 static int sip_reregister(const void *data) 
 {
 	/* if we are here, we know that we need to reregister. */
-	struct sip_registry *r= registry_addref((struct sip_registry *) data);
+	struct sip_registry *r= registry_addref((struct sip_registry *) data,"reg_addref from sip_reregister");
 
 	/* if we couldn't get a reference to the registry object, punt */
 	if (!r)
@@ -8395,7 +8418,7 @@
 
 	r->expire = -1;
 	__sip_do_register(r);
-	registry_unref(r);
+	registry_unref(r, "unreg the re-registered");
 	return 0;
 }
 
@@ -8418,7 +8441,7 @@
 {
 
 	/* if we are here, our registration timed out, so we'll just do it over */
-	struct sip_registry *r = registry_addref((struct sip_registry *) data);
+	struct sip_registry *r = registry_addref((struct sip_registry *) data, "registry_addref from sip_reg_timeout");
 	struct sip_pvt *p;
 	int res;
 
@@ -8442,8 +8465,8 @@
 		/* decouple the two objects */
 		/* p->registry == r, so r has 2 refs, and the unref won't take the object away */
 		if (p->registry)
-			p->registry = registry_unref(p->registry);
-		r->call = dialog_unref(r->call);
+			p->registry = registry_unref(p->registry,"p->registry unreffed");
+		r->call = dialog_unref(r->call,"unrefing r->call");
 	}
 	/* If we have a limit, stop registration and give up */
 	if (global_regattempts_max && r->regattempts > global_regattempts_max) {
@@ -8458,7 +8481,7 @@
 		res=transmit_register(r, SIP_REGISTER, NULL, NULL);
 	}
 	manager_event(EVENT_FLAG_SYSTEM, "Registry", "ChannelType: SIP\r\nUsername: %s\r\nDomain: %s\r\nStatus: %s\r\n", r->username, r->hostname, regstate2str(r->regstate));
-	registry_unref(r);
+	registry_unref(r,"unreffing registry_unref r");
 	return 0;
 }
 
@@ -8511,6 +8534,7 @@
 			 * probably DNS.  We need to reschedule a registration try */
 			ast_log(LOG_NOTICE,"Calling Sip_Destroy() from registry building for %s....\n", p->callid);
 			dialog_unlink_all(p, TRUE, TRUE);
+			dialog_unref(p, "unref dialog after unlink_all");
 			/* sip_destroy(p); */
 			if (r->timeout > -1) {
 				r->timeout = ast_sched_replace(r->timeout, sched, 
@@ -8531,8 +8555,8 @@
 		} else 	/* Set registry port to the port set from the peer definition/srv or default */
 			r->portno = ntohs(p->sa.sin_port);
 		ast_set_flag(&p->flags[0], SIP_OUTGOING);	/* Registration is outgoing call */
-		r->call = dialog_ref(p);		/* Save pointer to SIP dialog */
-		p->registry = registry_addref(r);	/* Add pointer to registry in packet */
+		r->call = dialog_ref(p,"transmit_register: setting dialog in registry r->call");		/* Save pointer to SIP dialog */
+		p->registry = registry_addref(r,"transmit_register: addref to p->registry in transmit_register");	/* Add pointer to registry in packet */
 		if (!ast_strlen_zero(r->secret))	/* Secret (password) */
 			ast_string_field_set(p, peersecret, r->secret);
 		if (!ast_strlen_zero(r->md5secret))
@@ -8878,30 +8902,13 @@
 
 	if (peer->selfdestruct ||
 	    ast_test_flag(&peer->flags[1], SIP_PAGE2_RTAUTOCLEAR)) {
-		struct sip_peer *peer3;
-		peer3 = ao2_find(peers, peer, OBJ_POINTER|OBJ_UNLINK);	/* Remove from peer list */
-		if (peer3) {
-			int rc = ao2_ref(peer3,0);
-			ast_log(LOG_NOTICE,"Peer %s removed from the name hash. Refc=%d\n", peer->name, rc);
-			if (peer3 != peer)
-				ast_log(LOG_WARNING,"Peer (%p) not equal to peer3 (%p); %s != %s;\n",
-						peer, peer3, peer->name, peer3->name);
-			unref_peer(peer);		/* Remove from memory */
-		} else {
-			ast_log(LOG_NOTICE,"Peer %s NOT found in the name hash table!\n", peer->name);
-		}
+		int rc = ao2_ref(peer,0,"");
+		ast_log(LOG_NOTICE,"Peer %s removing from the name hash. Refc=%d\n", peer->name, rc);
+		ao2_unlink(peers, peer, "ao2_unlink of peer from peers table");
 		
-		peer3 = ao2_find(peers_by_ip, peer, OBJ_POINTER|OBJ_UNLINK);	/* Remove from peer list */
-		if (peer3) {
-			int rc = ao2_ref(peer3,0);
-			ast_log(LOG_NOTICE,"Peer %s removed from the IP hash. Refc=%d\n", peer->name, rc);
-			if (peer3 != peer)
-				ast_log(LOG_WARNING,"IP Peer (%p) not equal to peer3 (%p); %s != %s;\n",
-						peer, peer3, peer->name, peer3->name);
-			unref_peer(peer);		/* Remove from memory */
-		} else {
-			ast_log(LOG_NOTICE,"Peer %s NOT found in the IP hash table!\n", peer->name);
-		}
+		rc = ao2_ref(peer,0,"");
+		ast_log(LOG_NOTICE,"Peer %s removing from the IP hash. Refc=%d\n", peer->name, rc);
+		ao2_unlink(peers_by_ip, peer, "ao2_unlink of peer from peers table");
 	}
 
 	return 0;
@@ -9470,7 +9477,7 @@
 
 	/* Request device state update */
 	ast_device_state_changed("SIP/%s", peer->name);
-	unref_peer(peer);
+	unref_peer(peer,"sip_peer_hold: from find_peer operation");
 	
 	return;
 }
@@ -9604,7 +9611,7 @@
 	if (!(peer && ast_apply_ha(peer->ha, sin))) {
 		/* Peer fails ACL check */
 		if (peer) {
-			unref_peer(peer);
+			unref_peer(peer,"register_verify: unref_peer: from find_peer operation");
 			peer = NULL;
 			res = AUTH_ACL_FAILED;
 		} else
@@ -9656,7 +9663,7 @@
 		/* Create peer if we have autocreate mode enabled */
 		peer = temp_peer(name);
 		if (peer) {
-			ao2_link(peers, peer);
+			ao2_link(peers, peer,"link peer into peer table");
 			sip_cancel_destroy(p);
 			switch (parse_register_contact(p, peer, req)) {
 			case PARSE_REGISTER_FAILED:
@@ -9714,7 +9721,7 @@
 		}
 	}
 	if (peer)
-		unref_peer(peer);
+		unref_peer(peer,"register_verify: unref_peer: tossing stack peer pointer at end of func");
 
 	return res;
 }
@@ -9952,10 +9959,10 @@
 	if (!ast_string_field_init(&tmp_dialog, 100)) {
 		ast_string_field_set(&tmp_dialog, callid, callid);
 	
-		sip_pvt_ptr = ao2_find(dialogs, &tmp_dialog, OBJ_POINTER);
+		sip_pvt_ptr = ao2_find(dialogs, &tmp_dialog, OBJ_POINTER, "ao2_find of dialog in dialogs table");
 		if (sip_pvt_ptr) {
 			char *ourtag = sip_pvt_ptr->tag;
-			int rc = ao2_ref(sip_pvt_ptr,0);
+			int rc = ao2_ref(sip_pvt_ptr,0,"");
 			ast_log(LOG_NOTICE,"Found dialog %s refcount=%d\n", sip_pvt_ptr->callid, rc);
 			/* Go ahead and lock it (and its owner) before returning */
 			sip_pvt_lock(sip_pvt_ptr);
@@ -10202,7 +10209,7 @@
 		ast_copy_string(referdata->refer_to, c, sizeof(referdata->refer_to));
 		ast_copy_string(referdata->referred_by, "", sizeof(referdata->referred_by));
 		ast_copy_string(referdata->refer_contact, "", sizeof(referdata->refer_contact));
-		referdata->refer_call = dialog_unref(referdata->refer_call);
+		referdata->refer_call = dialog_unref(referdata->refer_call, "unreffing referdata->refer_call");
 		/* Set new context */
 		ast_string_field_set(p, context, transfer_context);
 		return 0;
@@ -10429,7 +10436,7 @@
 		if (debug)
 			ast_verbose("Found user '%s' for '%s', but fails host access\n",
 				user->name, of);
-		unref_user(user);
+		unref_user(user,"unref_user: from check_auth_result from find_user call");
 		return AUTH_DONT_KNOW;
 	}
 	if (debug)
@@ -10511,7 +10518,7 @@
  			p->trtp = NULL;
  		}
 	}
-	unref_user(user);
+	unref_user(user,"unref_user from check_auth_result, at end");
 	return res;
 }
 
@@ -10587,7 +10594,7 @@
 		/* copy channel vars */
 		p->chanvars = copy_vars(peer->chanvars);
 		if (authpeer) {
-			ao2_ref(peer,1);
+			ao2_ref(peer,1,"copy pointer into (*authpeer)");
 			(*authpeer) = peer;	/* Add a ref to the object here, to keep it in memory a bit longer if it is realtime */
 		}
 
@@ -10638,7 +10645,7 @@
 		if (p->t38.peercapability)
 			p->t38.jointcapability &= p->t38.peercapability;
 	}
-	unref_peer(peer);
+	unref_peer(peer,"check_peer_ok: unref_peer: tossing temp ptr to peer from find_peer");
 	return res;
 }
 
@@ -11269,7 +11276,7 @@
 static int user_dump_func(void *userobj, void *arg, int flags)
 {
 	struct sip_user *user = userobj;
-	int refc = ao2_ref(userobj,0);
+	int refc = ao2_ref(userobj,0,"");
 	int *fd = arg;
 	char s[1000];
 	
@@ -11282,7 +11289,7 @@
 static int peer_dump_func(void *userobj, void *arg, int flags)
 {
 	struct sip_peer *peer = userobj;
-	int refc = ao2_ref(userobj,0);
+	int refc = ao2_ref(userobj,0,"");
 	int *fd = arg;
 	char s[1000];
 	
@@ -11312,9 +11319,9 @@
 	if (a->argc != 3)
 		return CLI_SHOWUSAGE;
 	ast_cli(a->fd, "-= User objects: %d static, %d realtime =-\n\n", suserobjs, ruserobjs);
-	ao2_callback(users, OBJ_NODATA, user_dump_func, &a->fd);
+	ao2_callback(users, OBJ_NODATA, user_dump_func, &a->fd,"initiate ao2_callback to dump users");
 	ast_cli(a->fd, "-= Peer objects: %d static, %d realtime, %d autocreate =-\n\n", speerobjs, rpeerobjs, apeerobjs);
-	ao2_callback(users, OBJ_NODATA, peer_dump_func, &a->fd);
+	ao2_callback(peers, OBJ_NODATA, peer_dump_func, &a->fd,"initiate ao2_callback to dump peers");
 	ast_cli(a->fd, "-= Registry objects: %d =-\n\n", regobjs);
 	ASTOBJ_CONTAINER_DUMP(a->fd, tmp, sizeof(tmp), &regl);
 	return CLI_SUCCESS;
@@ -11532,7 +11539,7 @@
 			}
 			if (pruned) {
 				ast_log(LOG_NOTICE,"Callback to PRUNE PEERS\n");
-				ao2_callback(peers, OBJ_NODATA|OBJ_UNLINK, peer_is_marked, 0);
+				ao2_callback(peers, OBJ_NODATA|OBJ_UNLINK, peer_is_marked, 0, "initiating callback to remove marked peers");
 				ast_cli(a->fd, "%d peers pruned.\n", pruned);
 			} else
 				ast_cli(a->fd, "No peers found to prune.\n");
@@ -11554,7 +11561,7 @@
 			}
 			if (pruned) {
 				ast_log(LOG_NOTICE,"Callback to PRUNE USERS\n");
-				ao2_callback(users, OBJ_NODATA|OBJ_UNLINK, user_is_marked, 0);
+				ao2_callback(users, OBJ_NODATA|OBJ_UNLINK, user_is_marked, 0, "callback to remove marked users");
 				ast_cli(a->fd, "%d users pruned.\n", pruned);
 			} else
 				ast_cli(a->fd, "No users found to prune.\n");
@@ -11564,27 +11571,30 @@
 		if (prunepeer) {
 			struct sip_peer tmp;
 			ast_copy_string(tmp.name, name, sizeof(tmp.name));
-			if ((peer = ao2_find(peers, &tmp, OBJ_POINTER|OBJ_UNLINK))) {
+			if ((peer = ao2_find(peers, &tmp, OBJ_POINTER|OBJ_UNLINK, "finding to unlink from peers"))) {
+				ao2_unlink(peers_by_ip,peer,"unlinking peer from peers_by_ip also");
 				if (!ast_test_flag(&peer->flags[1], SIP_PAGE2_RTCACHEFRIENDS)) {
 					ast_cli(a->fd, "Peer '%s' is not a Realtime peer, cannot be pruned.\n", name);
-					ao2_link(peers, peer);
-					ao2_link(peers_by_ip, peer);
+					/* put it back! */
+					ao2_link(peers, peer, "link peer into peer table");
+					ao2_link(peers_by_ip, peer, "link peer into peers_by_ip table");
 				} else
 					ast_cli(a->fd, "Peer '%s' pruned.\n", name);
-				unref_peer(peer);
+				unref_peer(peer,"sip_prune_realtime: unref_peer: tossing temp peer ptr");
 			} else
 				ast_cli(a->fd, "Peer '%s' not found.\n", name);
 		}
 		if (pruneuser) {
 			struct sip_user tmp;
 			ast_copy_string(tmp.name, name, sizeof(tmp.name));
-			if ((user = ao2_find(users, &tmp, OBJ_POINTER|OBJ_UNLINK))) {
+			if ((user = ao2_find(users, &tmp, OBJ_POINTER|OBJ_UNLINK, "finding to unlink from users table"))) {
 				if (!ast_test_flag(&user->flags[1], SIP_PAGE2_RTCACHEFRIENDS)) {
 					ast_cli(a->fd, "User '%s' is not a Realtime user, cannot be pruned.\n", name);
-					ao2_link(users, user);
+					/* put it back! */
+					ao2_link(users, user, "link user into users table");
 				} else
 					ast_cli(a->fd, "User '%s' pruned.\n", name);
-				unref_user(user);
+				unref_user(user,"unref_user: Tossing temp user ptr");
 			} else
 				ast_cli(a->fd, "User '%s' not found.\n", name);
 		}
@@ -11853,7 +11863,7 @@
  				ast_cli(fd, "                 %s = %s\n", v->name, v->value);
 		}
 		ast_cli(fd,"\n");
-		unref_peer(peer);
+		unref_peer(peer,"sip_show_peer: unref_peer: done with peer ptr");
 	} else  if (peer && type == 1) { /* manager listing */
 		char buf[256];
 		struct ast_str *mailbox_str = ast_str_alloca(512);
@@ -11930,7 +11940,7 @@
 			}
 		}
 
-		unref_peer(peer);
+		unref_peer(peer,"sip_show_peer: unref_peer: done with peer");
 
 	} else {
 		ast_cli(fd,"Peer %s not found.\n", argv[3]);
@@ -11998,7 +12008,7 @@
  				ast_cli(a->fd, "                 %s = %s\n", v->name, v->value);
 		}
 		ast_cli(a->fd,"\n");
-		unref_user(user);
+		unref_user(user,"unref_user from sip_show_user, near end");
 	} else {
 		ast_cli(a->fd,"User %s not found.\n", a->argv[3]);
 		ast_cli(a->fd,"\n");
@@ -12080,7 +12090,7 @@
 		} else {
 			ast_cli(a->fd, "Peer %s not registered\n", a->argv[2]);
 		}
-		unref_peer(peer);
+		unref_peer(peer,"sip_unregister: unref_peer via sip_unregister: done with peer from find_peer call");
 	} else {
 		ast_cli(a->fd, "Peer unknown: \'%s\'. Not unregistered.\n", a->argv[2]);
 	}
@@ -12378,7 +12388,7 @@
 		ast_cli(arg.fd, FORMAT3, "Peer", "User", "Call ID", "Extension", "Last state", "Type", "Mailbox");
 
 	/* iterate on the container and invoke the callback on each item */
-	ao2_callback(dialogs, OBJ_NODATA, show_channels_cb, &arg);
+	ao2_callback(dialogs, OBJ_NODATA, show_channels_cb, &arg,"callback to show channels");
 	
 	/* print summary information */
 	ast_cli(arg.fd, "%d active SIP %s%s\n", arg.numchans,
@@ -12410,10 +12420,10 @@
 	while ((cur = ao2_iterator_next(&i))) {
 		if (!strncasecmp(word, cur->callid, wordlen) && ++which > state) {
 			c = ast_strdup(cur->callid);
-			ao2_ref(cur,-1);
+			ao2_ref(cur,-1,"drop ref in iterator loop break");
 			break;
 		}
-		ao2_ref(cur,-1);
+		ao2_ref(cur,-1, "drop ref in iterator loop");
 	}
 	return c;
 }
@@ -12949,7 +12959,7 @@
 		sipdebug |= sip_debug_console;
 	}
 	if (peer)
-		unref_peer(peer);
+		unref_peer(peer,"sip_do_debug_peer: unref_peer, from find_peer call");
 	return CLI_SUCCESS;
 }
 
@@ -13044,6 +13054,7 @@
 			/* Maybe they're not registered, etc. */
 			ast_log(LOG_NOTICE,"Calling Sip_Destroy() from sip_notify for %s....\n", p->callid);
 			dialog_unlink_all(p, TRUE, TRUE);
+			dialog_unref(p, "unref dialog inside for loop" );
 			/* sip_destroy(p); */
 			ast_cli(a->fd, "Could not create address for '%s'\n", a->argv[i]);
 			continue;
@@ -13064,7 +13075,7 @@
 		ast_cli(a->fd, "Sending NOTIFY of type '%s' to '%s'\n", a->argv[2], a->argv[i]);
 		transmit_sip_request(p, &req);
 		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
-		dialog_unref(p);
+		dialog_unref(p,"unref pvt at end of for loop");
 	}
 
 	return CLI_SUCCESS;
@@ -13469,7 +13480,7 @@
 		}
 	}
 
-	unref_peer(peer);
+	unref_peer(peer,"unref_peer from function_sippeer, just before return");
 
 	return 0;
 }
@@ -14095,7 +14106,7 @@
 		}
 		r->timeout=-1;
 		r->call = NULL;
-		p->registry = NULL;
+		p->registry = registry_unref(p->registry,"unref registry entry p->registry"); /* are we erasing a ref? */
 		/* Let this one hang around until we have all the responses */
 		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
 		/* p->needdestroy = 1; */
@@ -14148,7 +14159,7 @@
 
 		/* Schedule re-registration before we expire */
 		r->expire = ast_sched_replace(r->expire, sched, expires_ms, sip_reregister, r); 
-		registry_unref(r);
+		registry_unref(r,"unref registry ptr r");
 	}

[... 1224 lines stripped ...]



More information about the asterisk-commits mailing list