From 233bf5ffdebd5a48f8e107a7d682e694dd2ec966 Mon Sep 17 00:00:00 2001
From: ehouse <ehouse@0782aaa5-4710-0410-8820-a96bf9123855>
Date: Sat, 28 Feb 2009 14:40:50 +0000
Subject: [PATCH] Fix crasher: removing ACK'd messages left list in
 inconsistent state. Candidate for moving to 4.2 branch if to be used for
 Palm.

---
 xwords4/common/comms.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/xwords4/common/comms.c b/xwords4/common/comms.c
index 978365e49..b9ccc0ad5 100644
--- a/xwords4/common/comms.c
+++ b/xwords4/common/comms.c
@@ -844,8 +844,9 @@ removeFromQueue( CommsCtxt* comms, XP_PlayerAddr channelNo, MsgID msgID )
                 __func__, msgID, channelNo, comms->queueLen );
 
     if ( (channelNo == 0) || !!getRecordFor(comms, NULL, channelNo) ) {
-        MsgQueueElem dummy;
-        MsgQueueElem* keep = &dummy;
+
+        MsgQueueElem* newHead = NULL;
+        MsgQueueElem* newTail = NULL;
         MsgQueueElem* elem;
         MsgQueueElem* next;
 
@@ -868,14 +869,16 @@ removeFromQueue( CommsCtxt* comms, XP_PlayerAddr channelNo, MsgID msgID )
             if ( !knownGood && (elem->msgID <= msgID) ) {
                 freeElem( comms, elem );
                 --comms->queueLen;
+            } else if ( NULL == newHead ) {
+                newHead = newTail = elem;
             } else {
-                keep->next = elem;
-                keep = elem;
+                newTail->next = elem;
+                newTail = elem;
             }
         }
 
-        keep->next = NULL;
-        comms->msgQueueHead = dummy.next;
+        comms->msgQueueHead = newHead;
+        comms->msgQueueTail = newTail;
     }
 
     XP_STATUSF( "%s: queueLen now %d", __func__, comms->queueLen );