2096: Fix the double-free of the antibot r=def- a=heinrich5991

I could not find an easy way to ensure that `AntibotDestroy` is only
being called once for each `AntibotInit` but still happening after all
the `CPlayer` destructors.

Co-authored-by: heinrich5991 <heinrich5991@gmail.com>
This commit is contained in:
bors[bot] 2020-03-24 15:16:24 +00:00 committed by GitHub
commit fb81000351
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 12 deletions

View file

@ -25,6 +25,15 @@ CAntibot::CAntibot()
}
CAntibot::~CAntibot()
{
// Check if `Init` was called. There is no easy way to prevent two
// destructors running without an `Init` call in between.
if(m_pGameContext)
{
AntibotDestroy();
free(g_Data.m_Map.m_pTiles);
g_Data.m_Map.m_pTiles = 0;
m_pGameContext = 0;
}
}
void CAntibot::Init(CGameContext *pGameContext)
{
@ -37,12 +46,6 @@ void CAntibot::Init(CGameContext *pGameContext)
AntibotInit(&g_Data);
Update();
}
void CAntibot::Shutdown()
{
AntibotDestroy();
free(g_Data.m_Map.m_pTiles);
g_Data.m_Map.m_pTiles = 0;
}
void CAntibot::Dump() { AntibotDump(); }
void CAntibot::Update()
{
@ -75,9 +78,6 @@ void CAntibot::Dump()
{
m_pGameContext->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "antibot", "antibot support not compiled in");
}
void CAntibot::Shutdown()
{
}
void CAntibot::Update()
{
}

View file

@ -11,7 +11,6 @@ public:
CAntibot();
~CAntibot();
void Init(CGameContext *pGameContext);
void Shutdown();
void Dump();
void OnPlayerInit(int ClientID);

View file

@ -3044,8 +3044,6 @@ void CGameContext::OnShutdown(bool FullShutdown)
if (FullShutdown)
Score()->OnShutdown();
m_Antibot.Shutdown();
if(m_TeeHistorianActive)
{
m_TeeHistorian.Finish();