tBug, with players being removed from a g_slist during the iteration over that same g_slist, fixed. (A copy of the list is now used.) - vaccinewars - be a doctor and try to vaccinate the world
(HTM) git clone git://src.adamsgaard.dk/vaccinewars
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 042c82570e7df175a373eb93ada6b2c5b8737e5d
(DIR) parent dd4fb7c859062ad35249c6d74147dd76230acfaa
(HTM) Author: Ben Webb <ben@salilab.org>
Date: Thu, 25 Apr 2002 13:31:01 +0000
Bug, with players being removed from a g_slist during the iteration over that
same g_slist, fixed. (A copy of the list is now used.)
Diffstat:
M src/serverside.c | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
---
(DIR) diff --git a/src/serverside.c b/src/serverside.c
t@@ -1083,7 +1083,7 @@ static int SetupLocalSocket(void)
void ServerLoop()
{
Player *tmp;
- GSList *list, *nextlist;
+ GSList *list, *nextlist, *listcp;
fd_set readfs, writefs, errorfs;
int topsock;
struct timeval timeout;
t@@ -1247,11 +1247,13 @@ void ServerLoop()
break;
}
}
- list = FirstServer;
- while (list) {
- nextlist = g_slist_next(list);
- tmp = (Player *)list->data;
- if (tmp) {
+
+ /* Check all players for data; iterate over a copy of the player list,
+ * as HandleServerPlayer may remove players from this list! */
+ listcp = g_slist_copy(FirstServer);
+ for (list = listcp; list; list = g_slist_next(list)) {
+ if (list->data && g_slist_find(FirstServer, list->data)) {
+ tmp = (Player *)list->data;
if (RespondToSelect(&tmp->NetBuf, &readfs, &writefs,
&errorfs, &DoneOK)) {
/* If any complete messages were read, process them */
t@@ -1261,15 +1263,16 @@ void ServerLoop()
/* The socket has been shut down, or the buffer was filled -
* remove player */
RemovePlayerFromServer(tmp);
- if (IsServerShutdown())
+ if (IsServerShutdown()) {
break;
- tmp = NULL;
+ }
}
}
- list = nextlist;
}
- if (list && IsServerShutdown())
+ g_slist_free(listcp);
+ if (IsServerShutdown()) {
break;
+ }
}
#ifndef CYGWIN
CloseLocalSocket(localsock);