From 63bdea798fa86fafa85cc5af939ed0c231436408 Mon Sep 17 00:00:00 2001 From: Noah Metzger Date: Wed, 22 May 2024 18:34:52 -0500 Subject: [PATCH] Fix server resource leaks during client reconnect Ensure client disconnect functions are called if a client reconnects without sending a disconnect command first. Fixes potential memory leaks, file handle leaks (particularly during UDP downloads), and bugs in unpatched mods (such as CTF flags disappearing from the game if the player holding it reconnects). --- code/server/sv_client.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/code/server/sv_client.c b/code/server/sv_client.c index a1eeaebf2..6e4619000 100644 --- a/code/server/sv_client.c +++ b/code/server/sv_client.c @@ -640,12 +640,15 @@ void SV_DirectConnect( const netadr_t *from ) { Com_Printf( "%s:reconnect\n", NET_AdrToString( from ) ); newcl = cl; - // this doesn't work because it nukes the players userinfo + if ( newcl->state >= CS_CONNECTED ) { + // call QVM disconnect function before calling connect again + // fixes issues such as disappearing CTF flags in unpatched mods + VM_Call( gvm, 1, GAME_CLIENT_DISCONNECT, newcl - svs.clients ); + + // don't leak memory or file handles due to e.g. downloads in progress + SV_FreeClient( newcl ); + } -// // disconnect the client from the game first so any flags the -// // player might have are dropped -// VM_Call( gvm, GAME_CLIENT_DISCONNECT, 1, newcl - svs.clients ); - // goto gotnewcl; } }