From 21e057e79df0fc8263f838d318f922af519a8e96 Mon Sep 17 00:00:00 2001
From: Russell Bryant <russell@russellbryant.com>
Date: Wed, 26 Dec 2007 16:51:16 +0000
Subject: [PATCH] Fix a bug in peer handling that caused multiple instances of
 a peer to end up in the peers container after a reload.  Somehow, this bug
 doesn't exist in 1.4 ... (closes issue #11626) (reported by pnlarsson,
 additional info from mvanbaak, fixed by me)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@94788 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 channels/chan_iax2.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index b424c608de..3aebc4f702 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -6454,7 +6454,7 @@ static void unlink_peer(struct iax2_peer *peer)
 		}
 	}
 
-	unlink_peer(peer);
+	ao2_unlink(peers, peer);
 }
 
 static void __expire_registry(const void *data)
@@ -9872,6 +9872,7 @@ static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, st
 			oldha = peer->ha;
 			peer->ha = NULL;
 		}
+		unlink_peer(peer);
 	} else if ((peer = ao2_alloc(sizeof(*peer), peer_destructor))) {
 		peer->expire = -1;
 		peer->pokeexpire = -1;
-- 
GitLab