From 5dd184da23abe1a9d8378a61fe13547d703cc9c9 Mon Sep 17 00:00:00 2001 From: Andrey Akhmichin Date: Fri, 26 Mar 2021 04:08:05 +0500 Subject: [PATCH] Fix memory leaks when parsing files. --- cl_dll/hud_spectator.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/cl_dll/hud_spectator.cpp b/cl_dll/hud_spectator.cpp index ce32e4e2..7cb8e1fe 100644 --- a/cl_dll/hud_spectator.cpp +++ b/cl_dll/hud_spectator.cpp @@ -824,6 +824,7 @@ bool CHudSpectator::ParseOverviewFile() char levelname[256] = { 0 }; char token[1024] = { 0 }; float height; + bool ret = false; char *afile = NULL, *pfile = NULL; @@ -843,7 +844,7 @@ bool CHudSpectator::ParseOverviewFile() strcpy( m_OverviewData.map, gEngfuncs.pfnGetLevelName() ); if( m_OverviewData.map[0] == '\0' ) - return false; // not active yet + return ret; // not active yet strcpy( levelname, m_OverviewData.map + 5 ); levelname[strlen( levelname ) - 4] = 0; @@ -855,7 +856,7 @@ bool CHudSpectator::ParseOverviewFile() if( !pfile ) { gEngfuncs.Con_DPrintf( "Couldn't open file %s. Using default values for overiew mode.\n", filename ); - return false; + return ret; } while( true ) @@ -872,7 +873,7 @@ bool CHudSpectator::ParseOverviewFile() if( stricmp( token, "{" ) ) { gEngfuncs.Con_Printf( "Error parsing overview file %s. (expected { )\n", filename ); - return false; + goto end; } pfile = gEngfuncs.COM_ParseFile( pfile, token ); @@ -912,7 +913,7 @@ bool CHudSpectator::ParseOverviewFile() else { gEngfuncs.Con_Printf( "Error parsing overview file %s. (%s unkown)\n", filename, token ); - return false; + goto end; } pfile = gEngfuncs.COM_ParseFile( pfile, token ); // parse next token @@ -924,7 +925,7 @@ bool CHudSpectator::ParseOverviewFile() if( m_OverviewData.layers == OVERVIEW_MAX_LAYERS ) { gEngfuncs.Con_Printf( "Error parsing overview file %s. ( too many layers )\n", filename ); - return false; + goto end; } pfile = gEngfuncs.COM_ParseFile( pfile, token ); @@ -932,7 +933,7 @@ bool CHudSpectator::ParseOverviewFile() if( stricmp( token, "{" ) ) { gEngfuncs.Con_Printf( "Error parsing overview file %s. (expected { )\n", filename ); - return false; + goto end; } pfile = gEngfuncs.COM_ParseFile( pfile, token ); @@ -953,7 +954,7 @@ bool CHudSpectator::ParseOverviewFile() else { gEngfuncs.Con_Printf( "Error parsing overview file %s. (%s unkown)\n", filename, token ); - return false; + goto end; } pfile = gEngfuncs.COM_ParseFile( pfile, token ); // parse next token @@ -963,12 +964,14 @@ bool CHudSpectator::ParseOverviewFile() } } - gEngfuncs.COM_FreeFile( afile ); - m_mapZoom = m_OverviewData.zoom; m_mapOrigin = m_OverviewData.origin; - return true; + ret = true; +end: + gEngfuncs.COM_FreeFile( afile ); + + return ret; } void CHudSpectator::LoadMapSprites()