From d14ce5ac392fa74fc1dfea0526334c608d25cec7 Mon Sep 17 00:00:00 2001 From: Jonathan Poncelet Date: Thu, 6 Jun 2019 13:02:22 +0100 Subject: [PATCH] SV_LoadProgs: Fixed potential memory leak if function failed (#46) SV_LoadProgs: Fixed potential memory leak if function failed --- engine/server/sv_game.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/engine/server/sv_game.c b/engine/server/sv_game.c index 55c07749..1e884ec9 100644 --- a/engine/server/sv_game.c +++ b/engine/server/sv_game.c @@ -5026,8 +5026,13 @@ qboolean SV_LoadProgs( const char *name ) svgame.pmove = &gpMove; svgame.globals = &gpGlobals; svgame.mempool = Mem_AllocPool( "Server Edicts Zone" ); + svgame.hInstance = COM_LoadLibrary( name, true, false ); - if( !svgame.hInstance ) return false; + if( !svgame.hInstance ) + { + Mem_FreePool(&svgame.mempool); + return false; + } // make sure what new dll functions is cleared memset( &svgame.dllFuncs2, 0, sizeof( svgame.dllFuncs2 )); @@ -5047,6 +5052,7 @@ qboolean SV_LoadProgs( const char *name ) COM_FreeLibrary( svgame.hInstance ); Con_Printf( S_ERROR "SV_LoadProgs: failed to get address of GetEntityAPI proc\n" ); svgame.hInstance = NULL; + Mem_FreePool(&svgame.mempool); return false; } @@ -5057,6 +5063,7 @@ qboolean SV_LoadProgs( const char *name ) COM_FreeLibrary( svgame.hInstance ); Con_Printf( S_ERROR "SV_LoadProgs: failed to get address of GiveFnptrsToDll proc\n" ); svgame.hInstance = NULL; + Mem_FreePool(&svgame.mempool); return false; } @@ -5089,6 +5096,7 @@ qboolean SV_LoadProgs( const char *name ) COM_FreeLibrary( svgame.hInstance ); Con_Printf( S_ERROR "SV_LoadProgs: couldn't get entity API\n" ); svgame.hInstance = NULL; + Mem_FreePool(&svgame.mempool); return false; } } @@ -5099,6 +5107,7 @@ qboolean SV_LoadProgs( const char *name ) COM_FreeLibrary( svgame.hInstance ); Con_Printf( S_ERROR "SV_LoadProgs: couldn't get entity API\n" ); svgame.hInstance = NULL; + Mem_FreePool(&svgame.mempool); return false; }