mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
Fix linked-list bug in removeFromQueue.
This commit is contained in:
parent
a8d3dbda66
commit
ff82dd61c0
1 changed files with 11 additions and 17 deletions
|
@ -656,13 +656,13 @@ removeFromQueue( CommsCtxt* comms, XP_PlayerAddr channelNo, MsgID msgID )
|
||||||
__func__, msgID, channelNo, comms->queueLen );
|
__func__, msgID, channelNo, comms->queueLen );
|
||||||
|
|
||||||
if ( (channelNo == 0) || !!getRecordFor(comms, channelNo) ) {
|
if ( (channelNo == 0) || !!getRecordFor(comms, channelNo) ) {
|
||||||
|
MsgQueueElem dummy;
|
||||||
|
MsgQueueElem* keep = &dummy;
|
||||||
MsgQueueElem* elem;
|
MsgQueueElem* elem;
|
||||||
MsgQueueElem* next;
|
MsgQueueElem* next;
|
||||||
MsgQueueElem* keep = NULL;
|
|
||||||
MsgQueueElem* tail = NULL;
|
|
||||||
MsgQueueElem* keepHead = NULL;
|
|
||||||
|
|
||||||
for ( elem = comms->msgQueueHead; !!elem; elem = next ) {
|
for ( elem = comms->msgQueueHead; !!elem; elem = next ) {
|
||||||
|
XP_Bool knownGood = XP_FALSE;
|
||||||
next = elem->next;
|
next = elem->next;
|
||||||
|
|
||||||
/* remove the 0-channel message if we've established a channel
|
/* remove the 0-channel message if we've established a channel
|
||||||
|
@ -671,30 +671,24 @@ removeFromQueue( CommsCtxt* comms, XP_PlayerAddr channelNo, MsgID msgID )
|
||||||
ACK -- IFF it isn't left over from the last game. */
|
ACK -- IFF it isn't left over from the last game. */
|
||||||
|
|
||||||
if ( (elem->channelNo == 0) && (channelNo != 0) ) {
|
if ( (elem->channelNo == 0) && (channelNo != 0) ) {
|
||||||
XP_ASSERT( !comms->isServer ); /* I've seen this fail once */
|
XP_ASSERT( !comms->isServer );
|
||||||
XP_ASSERT( elem->msgID == 0 ); /* will the check below pass? */
|
XP_ASSERT( elem->msgID == 0 );
|
||||||
} else if ( elem->channelNo != channelNo ) {
|
} else if ( elem->channelNo != channelNo ) {
|
||||||
continue;
|
knownGood = XP_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* here */
|
if ( !knownGood && (elem->msgID <= msgID) ) {
|
||||||
if ( elem->msgID <= msgID ) {
|
|
||||||
XP_FREE( comms->mpool, elem->msg );
|
XP_FREE( comms->mpool, elem->msg );
|
||||||
XP_FREE( comms->mpool, elem );
|
XP_FREE( comms->mpool, elem );
|
||||||
--comms->queueLen;
|
--comms->queueLen;
|
||||||
} else {
|
} else {
|
||||||
if ( !!keepHead ) {
|
keep->next = elem;
|
||||||
XP_ASSERT( !!keep );
|
|
||||||
keep->next = elem;
|
|
||||||
} else {
|
|
||||||
keepHead = elem;
|
|
||||||
}
|
|
||||||
keep = elem;
|
keep = elem;
|
||||||
tail = elem;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
comms->msgQueueHead = keepHead;
|
|
||||||
comms->msgQueueTail = tail;
|
keep->next = NULL;
|
||||||
|
comms->msgQueueHead = dummy.next;
|
||||||
}
|
}
|
||||||
|
|
||||||
XP_STATUSF( "%s: queueLen now %d", __func__, comms->queueLen );
|
XP_STATUSF( "%s: queueLen now %d", __func__, comms->queueLen );
|
||||||
|
|
Loading…
Reference in a new issue