From c3a75244573f3353d1e7c8624e85326fb2d0cbfe Mon Sep 17 00:00:00 2001
From: Walter Doekes <walter+asterisk@wjd.nu>
Date: Wed, 1 Oct 2014 10:10:41 +0000
Subject: [PATCH] chan_sip: Simplify some unref code by removing
 unlink_peer_from_tables.

ASTERISK-22945 #related
Reported by: ibercom
Patches:
  asterisk11-chan_sip-simplifies.patch uploaded by ibercom (License #6599)
........

Merged revisions 424181 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 424182 from http://svn.asterisk.org/svn/asterisk/branches/11
........

Merged revisions 424183 from http://svn.asterisk.org/svn/asterisk/branches/12
........

Merged revisions 424184 from http://svn.asterisk.org/svn/asterisk/branches/13


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@424185 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 channels/chan_sip.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 4ce17a1e15..57586e8cd2 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -3244,15 +3244,6 @@ static void unlink_all_peers_from_tables(void)
 	unlink_peers_from_tables(SIP_PEERS_ALL);
 }
 
-/* \brief Unlink single peer from all ao2 containers */
-static void unlink_peer_from_tables(struct sip_peer *peer)
-{
-	ao2_t_unlink(peers, peer, "ao2_unlink of peer from peers table");
-	if (!ast_sockaddr_isnull(&peer->addr)) {
-		ao2_t_unlink(peers_by_ip, peer, "ao2_unlink of peer from peers_by_ip table");
-	}
-}
-
 /*! \brief maintain proper refcounts for a sip_pvt's outboundproxy
  *
  * This function sets pvt's outboundproxy pointer to the one referenced
@@ -15869,11 +15860,12 @@ static int expire_register(const void *data)
 
 	if (peer->selfdestruct ||
 	    ast_test_flag(&peer->flags[1], SIP_PAGE2_RTAUTOCLEAR)) {
-		unlink_peer_from_tables(peer);
-	} else if (!ast_sockaddr_isnull(&peer->addr)) {
-		/* If we aren't self-destructing a temp_peer, we still need to unlink the peer
-		 * from the peers_by_ip table, otherwise we end up with multiple copies hanging
-		 * around each time a registration expires and the peer re-registers. */
+		ao2_t_unlink(peers, peer, "ao2_unlink of peer from peers table");
+	}
+	if (!ast_sockaddr_isnull(&peer->addr)) {
+		/* We still need to unlink the peer from the peers_by_ip table,
+		 * otherwise we end up with multiple copies hanging around each
+		 * time a registration expires and the peer re-registers. */
 		ao2_t_unlink(peers_by_ip, peer, "ao2_unlink of peer from peers_by_ip table");
 	}
 
-- 
GitLab