From d9a99af589ec10e0859ee2df11a31655457c44a9 Mon Sep 17 00:00:00 2001
From: Tilghman Lesher <tilghman@meg.abyt.es>
Date: Sun, 11 Dec 2005 01:26:09 +0000
Subject: [PATCH] Bug 5965 - major bug in AST_LIST_REMOVE

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7428 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 include/asterisk/linkedlists.h | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/include/asterisk/linkedlists.h b/include/asterisk/linkedlists.h
index cfe8462254..f687189e28 100644
--- a/include/asterisk/linkedlists.h
+++ b/include/asterisk/linkedlists.h
@@ -424,15 +424,16 @@ struct {								\
 #define AST_LIST_REMOVE(head, elm, field) do {			        \
 	if ((head)->first == (elm)) {					\
 		(head)->first = (elm)->field.next;			\
-	}								\
-	else {								\
+		if ((head)->last = (elm))			\
+			(head)->last = NULL;			\
+	} else {								\
 		typeof(elm) curelm = (head)->first;			\
 		while (curelm->field.next != (elm))			\
 			curelm = curelm->field.next;			\
 		curelm->field.next = (elm)->field.next;			\
+		if ((head)->last == curelm->field.next)			\
+			(head)->last = curelm;				\
 	}								\
-	if ((head)->last == elm)					\
-		(head)->last = NULL;					\
 } while (0)
 
 #endif /* _ASTERISK_LINKEDLISTS_H */
-- 
GitLab