[quake3-commits] r2081 - trunk/code/server

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Fri Jul 15 10:44:07 EDT 2011


Author: thilo
Date: 2011-07-15 10:44:06 -0400 (Fri, 15 Jul 2011)
New Revision: 2081

Modified:
   trunk/code/server/server.h
   trunk/code/server/sv_client.c
   trunk/code/server/sv_init.c
   trunk/code/server/sv_net_chan.c
Log:
- Revert back to Z_Malloc from Hunk_FreeTempMemory introduced in r2077 as Hunk_FreeTempMemory must be freed in LIFO order (#5079)
- Introduce SV_ClientFree() to prevent memory leaks r2077 was supposed to fix


Modified: trunk/code/server/server.h
===================================================================
--- trunk/code/server/server.h	2011-07-13 19:16:25 UTC (rev 2080)
+++ trunk/code/server/server.h	2011-07-15 14:44:06 UTC (rev 2081)
@@ -348,6 +348,7 @@
 void SV_UserinfoChanged( client_t *cl );
 
 void SV_ClientEnterWorld( client_t *client, usercmd_t *cmd );
+void SV_FreeClient(client_t *client);
 void SV_DropClient( client_t *drop, const char *reason );
 
 void SV_ExecuteClientCommand( client_t *cl, const char *s, qboolean clientOK );
@@ -466,4 +467,4 @@
 void SV_Netchan_Transmit( client_t *client, msg_t *msg);
 int SV_Netchan_TransmitNextFragment(client_t *client);
 qboolean SV_Netchan_Process( client_t *client, msg_t *msg );
-
+void SV_Netchan_FreeQueue(client_t *client);

Modified: trunk/code/server/sv_client.c
===================================================================
--- trunk/code/server/sv_client.c	2011-07-13 19:16:25 UTC (rev 2080)
+++ trunk/code/server/sv_client.c	2011-07-15 14:44:06 UTC (rev 2081)
@@ -579,7 +579,30 @@
 	}
 }
 
+/*
+=====================
+SV_FreeClient
 
+Destructor for data allocated in a client structure
+=====================
+*/
+void SV_FreeClient(client_t *client)
+{
+	int index;
+	
+	SV_Netchan_FreeQueue(client);
+	SV_CloseDownload(client);
+	
+	for(index = client->queuedVoipIndex; index < client->queuedVoipPackets; index++)
+	{
+		index %= ARRAY_LEN(client->voipPacket);
+		
+		Z_Free(client->voipPacket[index]);
+	}
+	
+	client->queuedVoipPackets = 0;
+}
+
 /*
 =====================
 SV_DropClient
@@ -612,17 +635,12 @@
 		}
 	}
 
-	// Kill any download
-	SV_CloseDownload( drop );
+	// Free all allocated data on the client structure
+	SV_FreeClient(drop);
 
 	// tell everyone why they got dropped
 	SV_SendServerCommand( NULL, "print \"%s" S_COLOR_WHITE " %s\n\"", drop->name, reason );
 
-	if (drop->download)	{
-		FS_FCloseFile( drop->download );
-		drop->download = 0;
-	}
-
 	// call the prog function for removing a client
 	// this will remove the body, among other things
 	VM_Call( gvm, GAME_CLIENT_DISCONNECT, drop - svs.clients );
@@ -797,7 +815,7 @@
 	// Free the temporary buffer space
 	for (i = 0; i < MAX_DOWNLOAD_WINDOW; i++) {
 		if (cl->downloadBlocks[i]) {
-			Hunk_FreeTempMemory(cl->downloadBlocks[i]);
+			Z_Free(cl->downloadBlocks[i]);
 			cl->downloadBlocks[i] = NULL;
 		}
 	}
@@ -1017,7 +1035,7 @@
 		curindex = (cl->downloadCurrentBlock % MAX_DOWNLOAD_WINDOW);
 
 		if (!cl->downloadBlocks[curindex])
-			cl->downloadBlocks[curindex] = Hunk_AllocateTempMemory(MAX_DOWNLOAD_BLKSIZE);
+			cl->downloadBlocks[curindex] = Z_Malloc(MAX_DOWNLOAD_BLKSIZE);
 
 		cl->downloadBlockSize[curindex] = FS_Read( cl->downloadBlocks[curindex], MAX_DOWNLOAD_BLKSIZE, cl->download );
 
@@ -1195,7 +1213,7 @@
 			MSG_WriteShort(msg, packet->len);
 			MSG_WriteData(msg, packet->data, packet->len);
 			
-			Hunk_FreeTempMemory(packet);
+			Z_Free(packet);
 		}
 
 		cl->queuedVoipPackets -= i;
@@ -1871,13 +1889,12 @@
 			continue;  // not addressed to this player.
 
 		// Transmit this packet to the client.
-		// !!! FIXME: I don't like this queueing system.
 		if (client->queuedVoipPackets >= ARRAY_LEN(client->voipPacket)) {
 			Com_Printf("Too many VoIP packets queued for client #%d\n", i);
 			continue;  // no room for another packet right now.
 		}
 
-		packet = Hunk_AllocateTempMemory(sizeof(*packet));
+		packet = Z_Malloc(sizeof(*packet));
 		packet->sender = sender;
 		packet->frames = frames;
 		packet->len = packetsize;

Modified: trunk/code/server/sv_init.c
===================================================================
--- trunk/code/server/sv_init.c	2011-07-13 19:16:25 UTC (rev 2080)
+++ trunk/code/server/sv_init.c	2011-07-15 14:44:06 UTC (rev 2081)
@@ -760,8 +760,14 @@
 	SV_ClearServer();
 
 	// free server static data
-	if ( svs.clients ) {
-		Z_Free( svs.clients );
+	if(svs.clients)
+	{
+		int index;
+		
+		for(index = 0; index < sv_maxclients->integer; index++)
+			SV_FreeClient(&svs.clients[index]);
+		
+		Z_Free(svs.clients);
 	}
 	Com_Memset( &svs, 0, sizeof( svs ) );
 

Modified: trunk/code/server/sv_net_chan.c
===================================================================
--- trunk/code/server/sv_net_chan.c	2011-07-13 19:16:25 UTC (rev 2080)
+++ trunk/code/server/sv_net_chan.c	2011-07-15 14:44:06 UTC (rev 2081)
@@ -130,8 +130,29 @@
 }
 #endif
 
+
+
 /*
 =================
+SV_Netchan_FreeQueue
+=================
+*/
+void SV_Netchan_FreeQueue(client_t *client)
+{
+	netchan_buffer_t *netbuf, *next;
+	
+	for(netbuf = client->netchan_start_queue; netbuf; netbuf = next)
+	{
+		next = netbuf->next;
+		Z_Free(netbuf);
+	}
+	
+	client->netchan_start_queue = NULL;
+	client->netchan_end_queue = &client->netchan_start_queue;
+}
+
+/*
+=================
 SV_Netchan_TransmitNextInQueue
 =================
 */
@@ -159,7 +180,7 @@
 	else
 		Com_DPrintf("#462 Netchan_TransmitNextFragment: remaining queued message\n");
 
-	Hunk_FreeTempMemory(netbuf);
+	Z_Free(netbuf);
 }
 
 /*
@@ -207,7 +228,7 @@
 	{
 		netchan_buffer_t *netbuf;
 		Com_DPrintf("#462 SV_Netchan_Transmit: unsent fragments, stacked\n");
-		netbuf = (netchan_buffer_t *) Hunk_AllocateTempMemory(sizeof(netchan_buffer_t));
+		netbuf = (netchan_buffer_t *) Z_Malloc(sizeof(netchan_buffer_t));
 		// store the msg, we can't store it encoded, as the encoding depends on stuff we still have to finish sending
 		MSG_Copy(&netbuf->msg, netbuf->msgBuffer, sizeof( netbuf->msgBuffer ), msg);
 		netbuf->next = NULL;



More information about the quake3-commits mailing list