Skip to content

Commit

Permalink
Fix memory leak on Custom Flags
Browse files Browse the repository at this point in the history
  • Loading branch information
atupone committed Apr 3, 2024
1 parent 5a1bbe3 commit 450b835
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions src/common/Flag.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -236,23 +236,8 @@ void kill()

void clearCustomFlags()
{
FlagSet::iterator itr, nitr;
for (int q = 0; q < (int)NumQualities; ++q)
{
for (itr = FlagType::flagSets[q].begin(); itr != FlagType::flagSets[q].end(); ++itr)
{
if ((*itr)->custom)
{
FlagType::getFlagMap().erase((*itr)->flagAbbv);
nitr = itr;
++nitr;
delete (*itr);
FlagType::flagSets[q].erase(itr);
itr = nitr;
if (itr == FlagType::flagSets[q].end()) break;
}
}
}
for (auto flag : FlagType::customFlags)
delete flag;
FlagType::customFlags.clear();
}
}
Expand Down Expand Up @@ -292,8 +277,7 @@ void* FlagType::packCustom(void* buf) const

const void* FlagType::unpackCustom(const void* buf, FlagType* &type)
{
uint8_t *abbv = new uint8_t[3];
abbv[0]=abbv[1]=abbv[2]=0;
unsigned char abbv[3] = {0, 0, 0};
buf = nboUnpackUByte(buf, abbv[0]);
buf = nboUnpackUByte(buf, abbv[1]);

Expand All @@ -319,7 +303,7 @@ const void* FlagType::unpackCustom(const void* buf, FlagType* &type)
assert(false); // shouldn't happen
}

type = new FlagType(sName, reinterpret_cast<const char*>(&abbv[0]),
type = new FlagType(sName, (const char *)abbv,
e, (ShotType)shot, (FlagQuality)quality, NoTeam, sHelp, true);
return buf;
}
Expand Down

0 comments on commit 450b835

Please sign in to comment.