Skip to content
Permalink
Browse files

Fix two allocate-deallocate mismatches. Found by ASan.

  • Loading branch information...
Philip Holzmann
Philip Holzmann committed May 5, 2019
1 parent c98c446 commit 2f837fc1a3aea961346b4dc43bb5a2222552ff14
Showing with 7 additions and 26 deletions.
  1. +1 −1 src/gui/C4GameOverDlg.cpp
  2. +4 −23 src/object/C4InfoCore.cpp
  3. +2 −2 src/object/C4InfoCore.h
@@ -242,7 +242,7 @@ C4GameOverDlg::C4GameOverDlg() : C4GUI::Dialog( (C4GUI::GetScreenWdt() < 800) ?
C4GameOverDlg::~C4GameOverDlg()
{
Application.Remove(this);
delete ppPlayerLists;
delete[] ppPlayerLists;
is_shown = false;
}

@@ -347,15 +347,13 @@ bool C4ObjectInfoCore::Save(C4Group &hGroup, C4DefList *pDefs)
{
UpdateCustomRanks(pDefs);
}
char *Buffer;
size_t BufferSize;
if (!Decompile(&Buffer, &BufferSize))
StdStrBuf Buffer;
if (!Decompile(Buffer))
{
return false;
}
if (!hGroup.Add(C4CFN_ObjectInfoCore, Buffer, BufferSize, false, true))
if (!hGroup.Add(C4CFN_ObjectInfoCore, Buffer, false, true))
{
delete [] Buffer;
return false;
}
return true;
@@ -402,32 +400,15 @@ bool C4ObjectInfoCore::Compile(const char *szSource)
return ret;
}

bool C4ObjectInfoCore::Decompile(char **ppOutput, size_t *ipSize)
bool C4ObjectInfoCore::Decompile(StdStrBuf &Buf)
{
StdStrBuf Buf;
if (!DecompileToBuf_Log<StdCompilerINIWrite>(
mkNamingAdapt(*this, "ObjectInfo"),
&Buf,
"ObjectInfo"))
{
if (ppOutput)
{
*ppOutput = nullptr;
}
if (ipSize)
{
*ipSize = 0;
}
return false;
}
if (ppOutput)
{
*ppOutput = Buf.GrabPointer();
}
if (ipSize)
{
*ipSize = Buf.getSize();
}
return true;
}

@@ -56,7 +56,7 @@ class C4ObjectInfoCore
void CompileFunc(StdCompiler *pComp);
protected:
bool Compile(const char *szSource);
bool Decompile(char **ppOutput, size_t *ipSize);
bool Decompile(StdStrBuf &Buf);

void UpdateCustomRanks(C4DefList *pDefs); // sets NextRankName and NextRankExp
};
@@ -105,7 +105,7 @@ class C4PlayerInfoCore
int32_t OldPrefAutoContextMenu;

// achievements indexed by achievement name and scenario
C4ScenarioParameters Achievements;
C4ScenarioParameters Achievements;
public:
void Default(C4RankSystem *pRanks=nullptr);
void Promote(int32_t iRank, C4RankSystem &rRanks);

0 comments on commit 2f837fc

Please sign in to comment.
You can’t perform that action at this time.