SV_LoadProgs: Fixed potential memory leak if function failed (#46)

SV_LoadProgs: Fixed potential memory leak if function failed
This commit is contained in:
Jonathan Poncelet 2019-06-06 13:02:22 +01:00 committed by Alibek Omarov
parent 76dae35955
commit d14ce5ac39

View File

@ -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;
}