Skip to content

Commit

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

void clearCustomFlags()
{
for (auto flag : FlagType::customFlags)
delete flag;
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;
}
}
}
FlagType::customFlags.clear();
}
}
Expand Down Expand Up @@ -277,7 +292,8 @@ void* FlagType::packCustom(void* buf) const

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

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

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

0 comments on commit d806700

Please sign in to comment.