Use delete[] for arrays allocated with new[].

This commit is contained in:
Scott Ludwig 2016-06-04 19:06:05 -07:00 committed by Nathan Fulton
parent e2e2283583
commit 95046aaaee
28 changed files with 72 additions and 71 deletions

View File

@ -54,7 +54,7 @@ const char *StringEncoder::QueryEncode(const char *s) {
}
*out = 0;
const char *result = base::Format::ToString("%s", buf);
delete buf;
delete[] buf;
return result;
}

View File

@ -212,7 +212,7 @@ void CutSceneForm::More()
// Start from the break next time around
m_pszText += pchBreak - pszT;
delete pszT;
delete[] pszT;
}
gpmfrmm->DrawFrame(false);
}
@ -305,4 +305,4 @@ bool CutSceneForm::OnPenEvent(Event *pevt)
return Form::OnPenEvent(pevt);
}
} // namespace wi
} // namespace wi

View File

@ -152,7 +152,7 @@ EcomForm::EcomForm()
EcomForm::~EcomForm()
{
if (m_pszText != NULL)
delete m_pszText;
delete[] m_pszText;
}
bool EcomForm::DoModal(char *pszMessage, int *pnResult, Sfx sfxShow, Sfx sfxHide)
@ -217,7 +217,7 @@ void EcomForm::More()
// Start from the break next time around
m_pszNext += pchBreak - pszT;
delete pszT;
delete[] pszT;
bool fMore = (*m_pszNext != 0);
if (fMore) {

View File

@ -1331,7 +1331,7 @@ bool GobMgr::Init(TCoord ctx, TCoord cty, int cpgobMax)
int cbT = sizeof(Gob **) * (m_cpgobMax + 1);
m_apgobMaster = (Gob **)gmmgr.AllocPtr(cbT);
if (m_apgobMaster == NULL) {
delete apgobMaster;
delete[] apgobMaster;
return false;
}
@ -1350,7 +1350,7 @@ bool GobMgr::Init(TCoord ctx, TCoord cty, int cpgobMax)
gmmgr.WritePtr(m_apgobMaster, 0, apgobMaster, cbT);
m_ppgobFreeTail = m_apgobMaster + m_cpgobMax;
m_ppgobFreeHead = m_apgobMaster;
delete apgobMaster;
delete[] apgobMaster;
// Allocate gidMap
@ -1372,11 +1372,11 @@ bool GobMgr::Init(TCoord ctx, TCoord cty, int cpgobMax)
cbT = m_ctx * m_cty * sizeof(Gid);
m_pgidMap = (Gid *)gmmgr.AllocPtr(cbT);
if (m_pgidMap == NULL) {
delete pgidMap;
delete[] pgidMap;
return false;
}
gmmgr.WritePtr(m_pgidMap, 0, pgidMap, cbT);
delete pgidMap;
delete[] pgidMap;
#ifdef INCL_VALIDATEHEAP
gmmgr.Validate();
@ -1958,7 +1958,7 @@ void GobMgr::AddGobToAreas(Gid gid, AreaMask am)
par->aare = aare;
} else {
memcpy(aare, par->aare, ELEMENTSIZE(aare) * par->careAlloc);
delete par->aare;
delete[] par->aare;
par->aare = aare;
}
@ -2182,7 +2182,7 @@ bool GobMgr::LoadAreas(IniReader *pini)
void GobMgr::FreeAreas()
{
for (int iar = 0; iar < m_car; iar++) {
delete m_aar[iar].aare;
delete[] m_aar[iar].aare;
m_aar[iar].aare = NULL;
}
m_car = 0;

View File

@ -16,6 +16,7 @@ Player gplrDummy;
PlayerMgr::PlayerMgr()
{
m_aplr = NULL;
Reset();
}

View File

@ -775,7 +775,7 @@ void SimUIForm::OnTimer(long tCurrent) {
memcpy(&pcc->amsgCommands, gcmdq.GetFirst(),
cmsg * sizeof(Message));
gptra->SendNetMessage(pcc);
delete pcc;
delete[] pcc;
}
gcmdq.Clear();
}

View File

@ -687,7 +687,7 @@ bool SocConnection::Poll()
if (cbT == SOCKET_ERROR) {
int err = WSAGetLastError();
if (err != WSAEWOULDBLOCK) {
delete pnm;
delete[] pnm;
HandleRecvError();
return false;
}
@ -704,7 +704,7 @@ bool SocConnection::Poll()
MpTrace("< %s", PszFromNetMessage(pnm));
m_pccb->OnReceive(this, pnm);
}
delete pnm;
delete[] pnm;
}
return true;

View File

@ -466,7 +466,7 @@ void EndMissionAction::OnMPEndMissionActionEvent(int nWinLose, Side side) {
EcomAction::~EcomAction()
{
delete m_pszMessage;
delete[] m_pszMessage;
}
bool EcomAction::Init(char *psz)

View File

@ -234,7 +234,7 @@ void UnitGob::ExitClass(UnitConsts *puntc)
delete puntc->pfrmMenu;
puntc->pfrmMenu = NULL;
delete puntc->szDescription;
delete[] puntc->szDescription;
puntc->szDescription = NULL;
}

View File

@ -37,7 +37,7 @@ bool UnitGroupMgr::Init(IniReader *pini)
for (int iug = 0; iug < m_cug; iug++) {
if (!m_aug[iug].Init(pini, iug)) {
delete m_aug;
delete[] m_aug;
m_aug = NULL;
return false;
}
@ -199,7 +199,7 @@ UnitGroup::UnitGroup()
UnitGroup::~UnitGroup()
{
delete m_aule;
delete[] m_aule;
// Delete Actions
@ -238,7 +238,7 @@ bool UnitGroup::LoadState(Stream *pstm)
UnitListEntry *aule = new UnitListEntry[cule];
Assert(aule != NULL, "out of memory!");
if (aule != NULL) {
delete m_aule;
delete[] m_aule;
m_aule = aule;
m_cule = cule;
}
@ -494,7 +494,7 @@ void UnitGroup::AddUnit(UnitGob *punt, bool fReplicant)
return;
memcpy(auleNew, m_aule, sizeof(UnitListEntry) * m_cule);
delete m_aule;
delete[] m_aule;
m_aule = auleNew;
m_aule[m_cule].gid = punt->GetId();
m_aule[m_cule].ut = punt->GetConsts()->ut;
@ -1442,4 +1442,4 @@ bool GuardVicinityUnitGroupAction::Perform(UnitGroup *pug)
return false;
}
} // namespace wi
} // namespace wi

View File

@ -30,7 +30,7 @@ DibBitmap::DibBitmap()
DibBitmap::~DibBitmap()
{
if (m_wf & kfDibFreeMem)
delete m_pb;
delete[] m_pb;
m_pb = NULL;
}

View File

@ -28,7 +28,7 @@ void CacheMgr::Exit()
// Free CacheEntry list
delete m_pceList;
delete[] m_pceList;
m_pceList = NULL;
m_pceFree = NULL;
}
@ -225,4 +225,4 @@ bool CacheMgr::MakeSpace(dword cb)
return false;
}
} // namespace wi
} // namespace wi

View File

@ -82,7 +82,7 @@ void FilePdbReader::Close()
Assert(m_pfil != NULL);
fclose(m_pfil);
m_pfil = NULL;
delete m_aphcRecordData;
delete[] m_aphcRecordData;
}
bool FilePdbReader::GetRecordSize(word nRec, word *pcb)

View File

@ -30,7 +30,7 @@ FogMap::FogMap()
FogMap::~FogMap()
{
delete m_panidWalls;
delete m_pbMap;
delete[] m_pbMap;
int n;
for (n = 0; n < 16; n++)
delete m_aptbm[n];

View File

@ -625,7 +625,7 @@ bool Game::LoadGameData()
if (gcxTile > 16) {
if (gcbScratch <= 10 * 1024) {
delete gpbScratch;
delete[] gpbScratch;
if (gcxTile == 32) {
gcbScratch = 35 * 1024;
} else {
@ -820,7 +820,7 @@ void Game::AddModeMatches(int nDepthData, int nSizeData, int nDepthOrGreater, in
continue;
if (m_amm != NULL) {
memcpy(pmm, m_amm, sizeof(ModeMatch) * m_cmm);
delete m_amm;
delete[] m_amm;
}
m_amm = pmm;
m_cmmAlloc += kcmmGrow;
@ -2066,7 +2066,7 @@ void Game::Exit()
delete gpdisp;
gpdisp = NULL;
delete m_amm;
delete[] m_amm;
m_amm = NULL;
m_cmm = 0;
m_cmmAlloc = 0;
@ -2082,7 +2082,7 @@ void Game::Exit()
DbLogExit();
#endif
delete gpbScratch;
delete[] gpbScratch;
gpbScratch = NULL;
m_fSimUninitialized = true;

View File

@ -38,7 +38,7 @@ bool HashTableCode::Init()
void HashTableCode::Exit()
{
DiscardHashEntries();
delete m_aphec;
delete[] m_aphec;
m_aphec = NULL;
// Free free list entries
@ -127,4 +127,4 @@ HashEntryCode *HashTableCode::FindEntry(dword hkName, int x, int y, int cx, int
gcam.Add((CacheEntry *)phec);
return phec;
}
}

View File

@ -186,7 +186,7 @@ void MemMgr::Init(dword cbDynReserve, dword cbMaxNeeded, dword *pcbTotal)
Heap *pheap = NewHeap(pv, (word)cbAlloc, false, 0, NULL);
if (pheap == NULL) {
delete (byte *)pv;
delete[] (byte *)pv;
break;
}
m_apheap[m_cheap++] = pheap;
@ -273,7 +273,7 @@ void MemMgr::Exit()
} else {
// Free the dyn chunk
delete pheap->pbHeap;
delete[] pheap->pbHeap;
}
delete pheap;
}
@ -295,7 +295,7 @@ void MemMgr::Exit()
for (int ihtab = 0; ihtab < m_chtab; ihtab++)
delete m_aphtab[ihtab];
delete m_aphtab;
delete[] m_aphtab;
m_chtab = 0;
m_chtabAlloced = 0;
m_aphtab = NULL;
@ -337,7 +337,7 @@ HandleTable *MemMgr::NewHandleTable()
return NULL;
if (m_aphtab != NULL) {
memcpy(aphtabT, m_aphtab, sizeof(HandleTable *) * m_chtabAlloced);
delete m_aphtab;
delete[] m_aphtab;
}
m_aphtab = aphtabT;
m_chtabAlloced += kchtabGrow;

View File

@ -62,9 +62,9 @@ void MemPdbReader::Close()
{
Assert(m_cMapped == 0);
Assert(m_pb != NULL);
delete m_pb;
delete[] m_pb;
m_pb = NULL;
delete m_aphcRecordData;
delete[] m_aphcRecordData;
m_aphcRecordData = NULL;
}
@ -238,7 +238,7 @@ void MemPdbReader::UnmapRecord(word nRec, void *pvCookie)
// Pointed to alloced object; unlock it
byte *pb = (byte *)pvCookie;
delete pb;
delete[] pb;
}
}

View File

@ -788,7 +788,7 @@ void SetHslAdjustedPalette(Palette *ppal, short nHueOffset, short nSatMultiplier
}
gpdisp->SetPalette(ppalMod);
delete ppalMod;
delete[] ppalMod;
}
// Takes byte-sized RGB values in the range from 0-255 and returns

View File

@ -1923,7 +1923,7 @@ RadioButtonBarControl::RadioButtonBarControl()
RadioButtonBarControl::~RadioButtonBarControl()
{
for (int i = 0; i < m_cLabels; i++) {
delete m_apszLabels[i];
delete[] m_apszLabels[i];
}
}

View File

@ -30,10 +30,10 @@ MissionList::~MissionList() {
while (ppdbiT->plvliFirst != NULL) {
LvlItem *plvliT = ppdbiT->plvliFirst;
ppdbiT->plvliFirst = ppdbiT->plvliFirst->plvliNext;
delete plvliT->pszFilename;
delete[] plvliT->pszFilename;
delete plvliT;
}
delete ppdbiT->pszTitle;
delete[] ppdbiT->pszTitle;
delete ppdbiT;
}
}

View File

@ -97,9 +97,9 @@ void SoundMgr::Exit()
m_apcmh[n].pb = NULL;
}
}
delete m_apcmh;
delete[] m_apcmh;
m_apcmh = NULL;
delete m_afmap;
delete[] m_afmap;
m_afmap = NULL;
m_cpcmh = 0;

View File

@ -47,7 +47,7 @@ void FreeSharedTBitmaps()
delete pshr->ptbm;
gmmgr.FreePtr(pshr);
}
delete gapshr;
delete[] gapshr;
gapshr = NULL;
gcshr = 0;
gcshrAlloc = 0;
@ -91,7 +91,7 @@ TBitmap *GetSharedTBitmap(char *pszFn)
return NULL;
if (gapshr != NULL) {
memcpy(ppshr, gapshr, sizeof(SharedRecord *) * gcshr);
delete gapshr;
delete[] gapshr;
}
gapshr = ppshr;
gcshrAlloc += kcshrGrow;
@ -166,14 +166,14 @@ bool TBitmap::InitClass()
else
s_ampscaiclrSide[i] = (dword *)gmmgr.AllocPtr(cbAlloc);
if (s_ampscaiclrSide[i] == NULL) {
delete mpscaiclrSideT;
delete[] mpscaiclrSideT;
return false;
}
gmmgr.WritePtr(s_ampscaiclrSide[i], 0, mpscaiclrSideT, cbAlloc);
if (iclrFirst == iclrLast && gcxTile >= 24)
gmmgr.WritePtr(s_ampscaiclrSide[i], cbAlloc, mpscaiclrSideT, cbAlloc);
}
delete mpscaiclrSideT;
delete[] mpscaiclrSideT;
// Done
@ -221,7 +221,7 @@ TBitmap::~TBitmap()
{
Assert(!(m_wf & kfTbShared));
delete m_ahc;
delete[] m_ahc;
m_ahc = NULL;
if (m_atbe != NULL) {
gmmgr.FreePtr(m_atbe);
@ -290,12 +290,12 @@ bool TBitmap::Init(File *pfil, word ib)
word cbAlloc = sizeof(TBitmapEntry) * m_ctbm;
TBitmapEntry *ptbeT = (TBitmapEntry *)gmmgr.AllocPtr(cbAlloc);
if (ptbeT == NULL) {
delete ptbe;
delete[] ptbe;
return false;
}
gmmgr.WritePtr(ptbeT, 0, ptbe, cbAlloc);
m_atbe = ptbeT;
delete ptbe;
delete[] ptbe;
// Remember file and offset

View File

@ -56,7 +56,7 @@ TerrainMap::~TerrainMap()
{
if (m_ptrmaph != NULL)
gpakr.UnmapFile(&m_fmap);
delete m_abBuffer;
delete[] m_abBuffer;
while (m_ppathhList != NULL)
RemovePathHead(m_ppathhList);
for (PathHead *ppathh = m_ppathhFreeList; ppathh != NULL; ) {
@ -801,7 +801,7 @@ Path::Path()
Path::~Path()
{
delete m_adir;
delete[] m_adir;
}
bool Path::Init(TerrainMap *ptrmap, TCoord txStart, TCoord tyStart, Direction *adir, int cdir)
@ -948,7 +948,7 @@ bool Path::Append(Path *ppath)
return false;
memcpy(adirNew, m_adir, m_cdirs);
memcpy(&adirNew[m_cdirs], ppath->m_adir, ppath->m_cdirs);
delete m_adir;
delete[] m_adir;
m_adir = adirNew;
m_cdirs += ppath->m_cdirs;
return true;
@ -963,7 +963,7 @@ bool Path::TrimEnd(int itptStart)
if (adirNew == NULL)
return false;
memcpy(adirNew, m_adir, cdirsNew);
delete m_adir;
delete[] m_adir;
m_adir = adirNew;
m_cdirs = cdirsNew;
return true;
@ -1209,4 +1209,4 @@ bool TrackPoint::IsBetterSort(TrackPoint *ptrkpA)
#endif
}
} // namespace wi
} // namespace wi

View File

@ -34,7 +34,7 @@ TileMap::~TileMap()
gpakr.UnmapFile(&m_fmapMiniTset);
if (m_apbTileData != NULL)
gmmgr.FreePtr(m_apbTileData);
delete m_apbDrawMap;
delete[] m_apbDrawMap;
}
bool TileMap::Load(char *psz, Size *psizPlayfield)
@ -105,11 +105,11 @@ bool TileMap::Load(char *psz, Size *psizPlayfield)
int cbT = sizeof(byte *) * m_cTiles;
m_apbTileData = (byte **)gmmgr.AllocPtr(cbT);
if (m_apbTileData == NULL) {
delete apbTileData;
delete[] apbTileData;
return false;
}
gmmgr.WritePtr(m_apbTileData, 0, apbTileData, cbT);
delete apbTileData;
delete[] apbTileData;
// Load mini tset
@ -235,4 +235,4 @@ void TileMap::Draw(DibBitmap *pbm, int x, int y, int cx, int cy, int xMap, int y
DrawTileMapThunk(m_apbDrawMap, m_ctx, m_cty, pbDib, sizDib.cx, pmnfo->cxLeftTile, pmnfo->cyTopTile, pmnfo->cxRightTile, pmnfo->cyBottomTile, pmnfo->ctxInside, pmnfo->ctyInside, gcxTile, gcyTile);
}
} // namespace wi
} // namespace wi

View File

@ -19,8 +19,8 @@ UpdateMap::UpdateMap()
UpdateMap::~UpdateMap()
{
delete m_afInvalid;
delete m_afInvalidDamage;
delete[] m_afInvalid;
delete[] m_afInvalidDamage;
}
bool UpdateMap::Init(Size *psiz)
@ -29,8 +29,8 @@ bool UpdateMap::Init(Size *psiz)
m_ctx = (psiz->cx + (gcxTile - 1)) / gcxTile + 1;
m_cty = (psiz->cy + (gcyTile - 1)) / gcyTile + 1;
int cb = m_ctx * m_cty;
delete m_afInvalid;
delete m_afInvalidDamage;
delete[] m_afInvalid;
delete[] m_afInvalidDamage;
m_afInvalid = new bool[cb];
if (m_afInvalid == NULL)
return false;
@ -606,7 +606,7 @@ bool UpdateMap::Scroll(int dx, int dy)
// Now scrolled. Cleanup
delete pfT;
delete[] pfT;
} else {
// Couldn't alloc temp buffer, so invalidate everything

View File

@ -279,7 +279,7 @@ XMsgGameNetMessage *XMsgGameNetMessage::FromBuffer(base::ByteBuffer& bb,
Assert(cbSav - bb.Length() == cbMsg);
if (cbSav - bb.Length() != cbMsg) {
delete pb;
delete[] pb;
return NULL;
}
@ -516,7 +516,7 @@ XMsgRoomGamePlayerNames *XMsgRoomGamePlayerNames::FromBuffer(
if (cbSav - bb.Length() != w) {
Assert();
delete anames;
delete[] anames;
return NULL;
}

View File

@ -195,7 +195,7 @@ struct XMsgShowMessage : public XMsg {
disconnect_ = disconnect;
}
~XMsgShowMessage() {
delete message_;
delete[] message_;
}
const char *message_;
dword ipRedirect_;
@ -219,7 +219,7 @@ struct XMsgLobbyAddRoom : public XMsg {
cGames_ = cGames;
}
~XMsgLobbyAddRoom() {
delete room_;
delete[] room_;
}
const char *room_;
dword roomid_;
@ -268,7 +268,7 @@ struct XMsgRoomGamePlayerNames : public XMsg
XMsgRoomGamePlayerNames(dword gameid, dword cnames,
PlayerName *anames) : XMsg(XMSG_ROOMGAMEPLAYERNAMES),
gameid_(gameid), cnames_(cnames), anames_(anames) { }
virtual ~XMsgRoomGamePlayerNames() { delete anames_; }
virtual ~XMsgRoomGamePlayerNames() { delete[] anames_; }
dword gameid_;
dword cnames_;
PlayerName *anames_;