Permalink
Browse files

Merge pull request #10 from devnexen/mem_leak_fixes

few memory leak fixes
  • Loading branch information...
mbasaglia committed Mar 15, 2017
2 parents 660b7e4 + 98953b0 commit b62b2258e66c1e4eb196759145ab68bf3fc742d6
@@ -1342,3 +1342,17 @@ void CL_ClearKeys()
memset( kb, 0, sizeof( kb ) );
}
void CL_ClearInput()
{
int i;
for ( i = 0; i < USERCMD_BUTTONS; ++i )
{
if ( registeredButtonCommands[ i ] )
{
Z_Free( registeredButtonCommands[i] );
registeredButtonCommands[i] = nullptr;
}
}
}
@@ -1676,6 +1676,23 @@ void CL_InitKeyCommands()
Cmd_AddCommand( "setkeydata", Key_SetKeyData_f );
}
void CL_ClearKeyBinding()
{
int team, keynum;
for ( team = 0; team < MAX_TEAMS; team++ )
{
for ( keynum = 0; keynum < MAX_KEYS; keynum++ )
{
if ( keys[ keynum ].binding[ team ] )
{
Z_Free( keys[ keynum ].binding[ team ] );
keys[ keynum ].binding[ team ] = nullptr;
}
}
}
}
/*
===================
CL_KeyEvent
@@ -1569,6 +1569,12 @@ static void CL_LoadRSAKeys()
Log::Notice( "%s", "Daemon RSA public-key found." );
}
static void CL_ClearRSAKeys()
{
rsa_private_key_clear( &private_key );
rsa_public_key_clear( &public_key );
}
/*
=================
@@ -3486,6 +3492,11 @@ void CL_Shutdown()
Cmd_RemoveCommand( "showip" );
Cmd_RemoveCommand( "model" );
CL_ClearKeyBinding();
CL_ClearInput();
CL_ClearRSAKeys();
// done.
CL_IRCWaitShutdown();
@@ -582,7 +582,9 @@ enum kbuttons_t
};
void CL_ClearKeys();
void CL_ClearKeyBinding();
void CL_ClearCmdButtons();
void CL_ClearInput();
void CL_InitInput();
void CL_SendCmd();
@@ -168,6 +168,36 @@ namespace Cvar {
return *cvars;
}
void Shutdown() {
CvarMap &cvars = GetCvarMap();
for (const auto &it: cvars) {
cvar_t &cvar = it.second->ccvar;
if (cvar.name)
{
Z_Free(cvar.name);
}
if (cvar.resetString)
{
Z_Free(cvar.resetString);
}
if (cvar.latchedString)
{
Z_Free(cvar.latchedString);
}
if (cvar.string)
{
Z_Free(cvar.string);
}
}
cvars.clear();
}
// A command created for each cvar, used for /<cvar>
class CvarCommand : public Cmd::CmdBase {
public:
@@ -88,6 +88,7 @@ namespace Cvar {
void SetValueCProxy(const std::string& cvarName, const std::string& value);
void SetCheatsAllowed(bool allowed);
void Shutdown();
//Kept as a reference for cvar flags
@@ -36,6 +36,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "LogSystem.h"
#include "System.h"
#include "CrashDump.h"
#include "CvarSystem.h"
#include <common/FileSystem.h>
#ifdef _WIN32
#include <windows.h>
@@ -281,6 +282,10 @@ static void Shutdown(bool error, Str::StringRef message)
Application::Shutdown(error, message);
if ( !error)
{
Cvar::Shutdown();
}
// Always run CON_Shutdown, because it restores the terminal to a usable state.
CON_Shutdown();
}
@@ -1710,6 +1710,7 @@ Com_Shutdown
*/
void Com_Shutdown()
{
NET_Shutdown();
if ( logfile )
{
FS_FCloseFile( logfile );
@@ -2031,8 +2031,15 @@ void NET_Init()
#endif
#ifdef HAVE_GEOIP
geoip_data_4 = NET_GeoIP_LoadData( GEOIP_COUNTRY_EDITION );
geoip_data_6 = NET_GeoIP_LoadData( GEOIP_COUNTRY_EDITION_V6 );
if (geoip_data_4 == nullptr)
{
geoip_data_4 = NET_GeoIP_LoadData( GEOIP_COUNTRY_EDITION );
}
if (geoip_data_6 == nullptr)
{
geoip_data_6 = NET_GeoIP_LoadData( GEOIP_COUNTRY_EDITION_V6 );
}
Log::Notice( "Loaded GeoIP data: ^%dIPv4 ^%dIPv6", geoip_data_4 ? 2 : 1, geoip_data_6 ? 2 : 1 );
#endif
@@ -2055,6 +2062,22 @@ void NET_Shutdown()
NET_Config( false );
#ifdef HAVE_GEOIP
if ( geoip_data_6 )
{
GeoIP_delete(geoip_data_6);
geoip_data_6 = nullptr;
}
if ( geoip_data_4 )
{
GeoIP_delete(geoip_data_4);
geoip_data_4 = nullptr;
}
GeoIP_cleanup();
#endif
#ifdef _WIN32
WSACleanup();
winsockInitialized = false;

0 comments on commit b62b225

Please sign in to comment.