- 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
This commit is contained in:
Thilo Schulz 2011-07-15 14:44:06 +00:00
parent 265d6e0374
commit f6d6ed4b30
4 changed files with 62 additions and 17 deletions

View file

@ -579,6 +579,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;
}
/*
=====================
@ -612,17 +635,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 );
@ -797,7 +815,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;
}
}
@ -1017,7 +1035,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 );
@ -1195,7 +1213,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;
@ -1871,13 +1889,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;