summaryrefslogtreecommitdiff
path: root/src/server/sv_client.c
diff options
context:
space:
mode:
authorThilo Schulz <arny@ats.s.bawue.de>2011-07-15 14:44:06 +0000
committerTim Angus <tim@ngus.net>2013-01-10 22:27:32 +0000
commita63482883e0e3487da4544699fa9c419cb17127d (patch)
treef711e82ecebdd863d52f290de8515e898282801b /src/server/sv_client.c
parentf7f76ecf69a2908810007940feff04a42121fd05 (diff)
- 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
Diffstat (limited to 'src/server/sv_client.c')
-rw-r--r--src/server/sv_client.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/src/server/sv_client.c b/src/server/sv_client.c
index b9b5e659..080349f8 100644
--- a/src/server/sv_client.c
+++ b/src/server/sv_client.c
@@ -370,6 +370,29 @@ gotnewcl:
}
}
+/*
+=====================
+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;
+}
/*
=====================
@@ -398,17 +421,12 @@ void SV_DropClient( client_t *drop, const char *reason ) {
}
}
- // 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 );
@@ -574,7 +592,7 @@ static void SV_CloseDownload( client_t *cl ) {
// 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;
}
}
@@ -766,7 +784,7 @@ int SV_WriteDownloadToClient(client_t *cl, msg_t *msg)
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 );
@@ -944,7 +962,7 @@ void SV_WriteVoipToClient( client_t *cl, msg_t *msg )
MSG_WriteShort(msg, packet->len);
MSG_WriteData(msg, packet->data, packet->len);
- Hunk_FreeTempMemory(packet);
+ Z_Free(packet);
}
cl->queuedVoipPackets -= i;
@@ -1626,13 +1644,12 @@ void SV_UserVoip( client_t *cl, msg_t *msg ) {
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;