Nullify deleted pointers.

master
archshift 2014-06-19 01:49:56 -07:00
parent 35a4aa419c
commit e8143de01b
35 changed files with 75 additions and 18 deletions

View File

@ -1765,6 +1765,7 @@ static int tolua_cWorld_ChunkStay(lua_State * tolua_S)
if (!ChunkStay->AddChunks(2)) if (!ChunkStay->AddChunks(2))
{ {
delete ChunkStay; delete ChunkStay;
ChunkStay = NULL;
return 0; return 0;
} }

View File

@ -1571,6 +1571,7 @@ bool cPluginLua::AddHookRef(int a_HookType, int a_FnRefIdx)
LOGWARNING("Plugin %s tried to add a hook %d with bad handler function.", GetName().c_str(), a_HookType); LOGWARNING("Plugin %s tried to add a hook %d with bad handler function.", GetName().c_str(), a_HookType);
m_LuaState.LogStackTrace(); m_LuaState.LogStackTrace();
delete Ref; delete Ref;
Ref = NULL;
return false; return false;
} }

View File

@ -1467,6 +1467,7 @@ void cPluginManager::RemovePlugin(cPlugin * a_Plugin)
a_Plugin->OnDisable(); a_Plugin->OnDisable();
} }
delete a_Plugin; delete a_Plugin;
a_Plugin = NULL;
} }

View File

@ -295,9 +295,9 @@ cBlockArea::~cBlockArea()
void cBlockArea::Clear(void) void cBlockArea::Clear(void)
{ {
delete[] m_BlockTypes; m_BlockTypes = NULL; delete[] m_BlockTypes; m_BlockTypes = NULL;
delete[] m_BlockMetas; m_BlockMetas = NULL; delete[] m_BlockMetas; m_BlockMetas = NULL;
delete[] m_BlockLight; m_BlockLight = NULL; delete[] m_BlockLight; m_BlockLight = NULL;
delete[] m_BlockSkyLight; m_BlockSkyLight = NULL; delete[] m_BlockSkyLight; m_BlockSkyLight = NULL;
m_Origin.Set(0, 0, 0); m_Origin.Set(0, 0, 0);
m_Size.Set(0, 0, 0); m_Size.Set(0, 0, 0);
@ -1013,8 +1013,8 @@ void cBlockArea::RotateCCW(void)
} // for x } // for x
std::swap(m_BlockTypes, NewTypes); std::swap(m_BlockTypes, NewTypes);
std::swap(m_BlockMetas, NewMetas); std::swap(m_BlockMetas, NewMetas);
delete[] NewTypes; delete[] NewTypes; NewTypes = NULL;
delete[] NewMetas; delete[] NewMetas; NewMetas = NULL;
std::swap(m_Size.x, m_Size.z); std::swap(m_Size.x, m_Size.z);
} }
@ -1058,8 +1058,8 @@ void cBlockArea::RotateCW(void)
} // for x } // for x
std::swap(m_BlockTypes, NewTypes); std::swap(m_BlockTypes, NewTypes);
std::swap(m_BlockMetas, NewMetas); std::swap(m_BlockMetas, NewMetas);
delete[] NewTypes; delete[] NewTypes; NewTypes = NULL;
delete[] NewMetas; delete[] NewMetas; NewMetas = NULL;
std::swap(m_Size.x, m_Size.z); std::swap(m_Size.x, m_Size.z);
} }
@ -1206,7 +1206,7 @@ void cBlockArea::RotateCCWNoMeta(void)
} // for z } // for z
} // for x } // for x
std::swap(m_BlockTypes, NewTypes); std::swap(m_BlockTypes, NewTypes);
delete[] NewTypes; delete[] NewTypes; NewTypes = NULL;
} }
if (HasBlockMetas()) if (HasBlockMetas())
{ {
@ -1224,7 +1224,7 @@ void cBlockArea::RotateCCWNoMeta(void)
} // for z } // for z
} // for x } // for x
std::swap(m_BlockMetas, NewMetas); std::swap(m_BlockMetas, NewMetas);
delete[] NewMetas; delete[] NewMetas; NewMetas = NULL;
} }
std::swap(m_Size.x, m_Size.z); std::swap(m_Size.x, m_Size.z);
} }
@ -1251,7 +1251,7 @@ void cBlockArea::RotateCWNoMeta(void)
} // for x } // for x
} // for z } // for z
std::swap(m_BlockTypes, NewTypes); std::swap(m_BlockTypes, NewTypes);
delete[] NewTypes; delete[] NewTypes; NewTypes = NULL;
} }
if (HasBlockMetas()) if (HasBlockMetas())
{ {
@ -1269,7 +1269,7 @@ void cBlockArea::RotateCWNoMeta(void)
} // for x } // for x
} // for z } // for z
std::swap(m_BlockMetas, NewMetas); std::swap(m_BlockMetas, NewMetas);
delete[] NewMetas; delete[] NewMetas; NewMetas = NULL;
} }
std::swap(m_Size.x, m_Size.z); std::swap(m_Size.x, m_Size.z);
} }
@ -1658,6 +1658,7 @@ bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
if (m_BlockMetas == NULL) if (m_BlockMetas == NULL)
{ {
delete[] m_BlockTypes; delete[] m_BlockTypes;
m_BlockTypes = NULL;
return false; return false;
} }
} }
@ -1667,7 +1668,9 @@ bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
if (m_BlockLight == NULL) if (m_BlockLight == NULL)
{ {
delete[] m_BlockMetas; delete[] m_BlockMetas;
m_BlockMetas = NULL;
delete[] m_BlockTypes; delete[] m_BlockTypes;
m_BlockTypes = NULL;
return false; return false;
} }
} }
@ -1677,8 +1680,11 @@ bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
if (m_BlockSkyLight == NULL) if (m_BlockSkyLight == NULL)
{ {
delete[] m_BlockLight; delete[] m_BlockLight;
m_BlockLight = NULL;
delete[] m_BlockMetas; delete[] m_BlockMetas;
m_BlockMetas = NULL;
delete[] m_BlockTypes; delete[] m_BlockTypes;
m_BlockTypes = NULL;
return false; return false;
} }
} }

View File

@ -34,6 +34,7 @@ cBlockInfo::cBlockInfo()
cBlockInfo::~cBlockInfo() cBlockInfo::~cBlockInfo()
{ {
delete m_Handler; delete m_Handler;
m_Handler = NULL;
} }

View File

@ -165,6 +165,7 @@ cByteBuffer::~cByteBuffer()
{ {
CheckValid(); CheckValid();
delete[] m_Buffer; delete[] m_Buffer;
m_Buffer = NULL;
} }

View File

@ -152,7 +152,9 @@ cChunk::~cChunk()
m_NeighborZP->m_NeighborZM = NULL; m_NeighborZP->m_NeighborZM = NULL;
} }
delete m_WaterSimulatorData; delete m_WaterSimulatorData;
m_WaterSimulatorData = NULL;
delete m_LavaSimulatorData; delete m_LavaSimulatorData;
m_LavaSimulatorData = NULL;
} }
@ -596,6 +598,7 @@ void cChunk::Tick(float a_Dt)
cEntity * ToDelete = *itr; cEntity * ToDelete = *itr;
itr = m_Entities.erase(itr); itr = m_Entities.erase(itr);
delete ToDelete; delete ToDelete;
ToDelete = NULL;
continue; continue;
} }
++itr; ++itr;
@ -1417,6 +1420,7 @@ void cChunk::SetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType,
BlockEntity->Destroy(); BlockEntity->Destroy();
RemoveBlockEntity(BlockEntity); RemoveBlockEntity(BlockEntity);
delete BlockEntity; delete BlockEntity;
BlockEntity = NULL;
} }
// If the new block is a block entity, create the entity object: // If the new block is a block entity, create the entity object:

View File

@ -59,6 +59,7 @@ cCraftingGrid::cCraftingGrid(const cCraftingGrid & a_Original) :
cCraftingGrid::~cCraftingGrid() cCraftingGrid::~cCraftingGrid()
{ {
delete[] m_Items; delete[] m_Items;
m_Items = NULL;
} }

View File

@ -146,6 +146,7 @@ cPlayer::~cPlayer(void)
m_ClientHandle = NULL; m_ClientHandle = NULL;
delete m_InventoryWindow; delete m_InventoryWindow;
m_InventoryWindow = NULL;
LOGD("Player %p deleted", this); LOGD("Player %p deleted", this);
} }

View File

@ -42,6 +42,7 @@ cFurnaceRecipe::~cFurnaceRecipe()
{ {
ClearRecipes(); ClearRecipes();
delete m_pState; delete m_pState;
m_pState = NULL;
} }
@ -187,7 +188,9 @@ void cFurnaceRecipe::ClearRecipes(void)
{ {
Recipe R = *itr; Recipe R = *itr;
delete R.In; delete R.In;
R.In = NULL;
delete R.Out; delete R.Out;
R.Out = NULL;
} }
m_pState->Recipes.clear(); m_pState->Recipes.clear();
@ -195,6 +198,7 @@ void cFurnaceRecipe::ClearRecipes(void)
{ {
Fuel F = *itr; Fuel F = *itr;
delete F.In; delete F.In;
F.In = NULL;
} }
m_pState->Fuel.clear(); m_pState->Fuel.clear();
} }

View File

@ -135,7 +135,9 @@ cBioGenCache::cBioGenCache(cBiomeGen * a_BioGenToCache, int a_CacheSize) :
cBioGenCache::~cBioGenCache() cBioGenCache::~cBioGenCache()
{ {
delete[] m_CacheData; delete[] m_CacheData;
m_CacheData = NULL;
delete[] m_CacheOrder; delete[] m_CacheOrder;
m_CacheOrder = NULL;
} }

View File

@ -672,7 +672,9 @@ cCompoGenCache::cCompoGenCache(cTerrainCompositionGen & a_Underlying, int a_Cach
cCompoGenCache::~cCompoGenCache() cCompoGenCache::~cCompoGenCache()
{ {
delete[] m_CacheData; delete[] m_CacheData;
m_CacheData = NULL;
delete[] m_CacheOrder; delete[] m_CacheOrder;
m_CacheOrder = NULL;
} }

View File

@ -142,7 +142,9 @@ cHeiGenCache::cHeiGenCache(cTerrainHeightGen & a_HeiGenToCache, int a_CacheSize)
cHeiGenCache::~cHeiGenCache() cHeiGenCache::~cHeiGenCache()
{ {
delete[] m_CacheData; delete[] m_CacheData;
m_CacheData = NULL;
delete[] m_CacheOrder; delete[] m_CacheOrder;
m_CacheOrder = NULL;
} }

View File

@ -30,10 +30,12 @@ cGroupManager::~cGroupManager()
for( GroupMap::iterator itr = m_pState->Groups.begin(); itr != m_pState->Groups.end(); ++itr ) for( GroupMap::iterator itr = m_pState->Groups.begin(); itr != m_pState->Groups.end(); ++itr )
{ {
delete itr->second; delete itr->second;
itr->second = NULL;
} }
m_pState->Groups.clear(); m_pState->Groups.clear();
delete m_pState; delete m_pState;
m_pState = NULL;
} }

View File

@ -28,6 +28,7 @@ cHTTPConnection::~cHTTPConnection()
{ {
// LOGD("HTTP: Connection deleting: %p", this); // LOGD("HTTP: Connection deleting: %p", this);
delete m_CurrentRequest; delete m_CurrentRequest;
m_CurrentRequest = NULL;
} }

View File

@ -28,6 +28,7 @@ cItemGrid::cItemGrid(int a_Width, int a_Height) :
cItemGrid::~cItemGrid() cItemGrid::~cItemGrid()
{ {
delete[] m_Slots; delete[] m_Slots;
m_Slots = NULL;
} }

View File

@ -69,6 +69,7 @@ public:
if (!Arrow->Initialize(*a_Player->GetWorld())) if (!Arrow->Initialize(*a_Player->GetWorld()))
{ {
delete Arrow; delete Arrow;
Arrow = NULL;
return; return;
} }
a_Player->GetWorld()->BroadcastSpawnEntity(*Arrow); a_Player->GetWorld()->BroadcastSpawnEntity(*Arrow);

View File

@ -260,6 +260,7 @@ void cItemHandler::Deinit()
for(int i = 0; i < 2267; i++) for(int i = 0; i < 2267; i++)
{ {
delete m_ItemHandler[i]; delete m_ItemHandler[i];
m_ItemHandler[i] = NULL;
} }
memset(m_ItemHandler, 0, sizeof(m_ItemHandler)); // Don't leave any dangling pointers around, just in case memset(m_ItemHandler, 0, sizeof(m_ItemHandler)); // Don't leave any dangling pointers around, just in case
m_HandlerInitialized = false; m_HandlerInitialized = false;

View File

@ -37,6 +37,7 @@ public:
if (!ItemFrame->Initialize(*a_World)) if (!ItemFrame->Initialize(*a_World))
{ {
delete ItemFrame; delete ItemFrame;
ItemFrame = NULL;
return false; return false;
} }

View File

@ -57,6 +57,7 @@ cMCLogger::~cMCLogger()
{ {
m_Log->Log("--- Stopped Log ---\n"); m_Log->Log("--- Stopped Log ---\n");
delete m_Log; delete m_Log;
m_Log = NULL;
if (this == s_MCLogger) if (this == s_MCLogger)
{ {
s_MCLogger = NULL; s_MCLogger = NULL;

View File

@ -47,6 +47,7 @@ void cBlaze::Attack(float a_Dt)
if (!FireCharge->Initialize(*m_World)) if (!FireCharge->Initialize(*m_World))
{ {
delete FireCharge; delete FireCharge;
FireCharge = NULL;
return; return;
} }
m_World->BroadcastSpawnEntity(*FireCharge); m_World->BroadcastSpawnEntity(*FireCharge);

View File

@ -49,6 +49,7 @@ void cGhast::Attack(float a_Dt)
if (!GhastBall->Initialize(*m_World)) if (!GhastBall->Initialize(*m_World))
{ {
delete GhastBall; delete GhastBall;
GhastBall = NULL;
return; return;
} }
m_World->BroadcastSpawnEntity(*GhastBall); m_World->BroadcastSpawnEntity(*GhastBall);

View File

@ -84,6 +84,7 @@ void cSkeleton::Attack(float a_Dt)
if (!Arrow->Initialize(*m_World)) if (!Arrow->Initialize(*m_World))
{ {
delete Arrow; delete Arrow;
Arrow = NULL;
return; return;
} }
m_World->BroadcastSpawnEntity(*Arrow); m_World->BroadcastSpawnEntity(*Arrow);

View File

@ -47,6 +47,7 @@ cMonsterConfig::cMonsterConfig(void)
cMonsterConfig::~cMonsterConfig() cMonsterConfig::~cMonsterConfig()
{ {
delete m_pState; delete m_pState;
m_pState = NULL;
} }

View File

@ -877,6 +877,7 @@ void cPerlinNoise::Generate2D(
if (ShouldFreeWorkspace) if (ShouldFreeWorkspace)
{ {
delete[] a_Workspace; delete[] a_Workspace;
a_Workspace = NULL;
} }
} }
@ -943,6 +944,7 @@ void cPerlinNoise::Generate3D(
if (ShouldFreeWorkspace) if (ShouldFreeWorkspace)
{ {
delete[] a_Workspace; delete[] a_Workspace;
a_Workspace = NULL;
} }
} }
@ -1045,6 +1047,7 @@ void cRidgedMultiNoise::Generate2D(
if (ShouldFreeWorkspace) if (ShouldFreeWorkspace)
{ {
delete[] a_Workspace; delete[] a_Workspace;
a_Workspace = NULL;
} }
} }
@ -1111,6 +1114,7 @@ void cRidgedMultiNoise::Generate3D(
if (ShouldFreeWorkspace) if (ShouldFreeWorkspace)
{ {
delete[] a_Workspace; delete[] a_Workspace;
a_Workspace = NULL;
} }
} }

View File

@ -71,6 +71,7 @@ cEvent::~cEvent()
{ {
sem_destroy(m_Event); sem_destroy(m_Event);
delete m_Event; delete m_Event;
m_Event = NULL;
} }
#endif #endif
} }

View File

@ -61,6 +61,7 @@ bool cSocketThreads::AddClient(const cSocket & a_Socket, cCallback * a_Client)
// There was an error launching the thread (but it was already logged along with the reason) // There was an error launching the thread (but it was already logged along with the reason)
LOGERROR("A new cSocketThread failed to start"); LOGERROR("A new cSocketThread failed to start");
delete Thread; delete Thread;
Thread = NULL;
return false; return false;
} }
Thread->AddClient(a_Socket, a_Client); Thread->AddClient(a_Socket, a_Client);

View File

@ -66,11 +66,13 @@ cThread::cThread( ThreadFunc a_ThreadFunction, void* a_Param, const char* a_Thre
cThread::~cThread() cThread::~cThread()
{ {
delete m_Event; delete m_Event;
m_Event = NULL;
if( m_StopEvent ) if( m_StopEvent )
{ {
m_StopEvent->Wait(); m_StopEvent->Wait();
delete m_StopEvent; delete m_StopEvent;
m_StopEvent = NULL;
} }
} }

View File

@ -37,6 +37,7 @@ cProtocolRecognizer::cProtocolRecognizer(cClientHandle * a_Client) :
cProtocolRecognizer::~cProtocolRecognizer() cProtocolRecognizer::~cProtocolRecognizer()
{ {
delete m_Protocol; delete m_Protocol;
m_Protocol = NULL;
} }

View File

@ -326,6 +326,7 @@ void cServer::OnConnectionAccepted(cSocket & a_Socket)
LOGERROR("Client \"%s\" cannot be handled, server probably unstable", ClientIP.c_str()); LOGERROR("Client \"%s\" cannot be handled, server probably unstable", ClientIP.c_str());
a_Socket.CloseSocket(); a_Socket.CloseSocket();
delete NewHandle; delete NewHandle;
NewHandle = NULL;
return; return;
} }

View File

@ -169,7 +169,8 @@ Direction cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a
X = Pos->x; X = Pos->x;
Z = Pos->z; Z = Pos->z;
} }
}else if(BlockID == E_BLOCK_AIR) }
else if(BlockID == E_BLOCK_AIR)
{ {
LowestPoint = 9; //This always dominates LowestPoint = 9; //This always dominates
X = Pos->x; X = Pos->x;
@ -177,6 +178,7 @@ Direction cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a
} }
delete Pos; delete Pos;
Pos = NULL;
} }
if (LowestPoint == m_World.GetBlockMeta(a_X, a_Y, a_Z)) if (LowestPoint == m_World.GetBlockMeta(a_X, a_Y, a_Z))

View File

@ -524,6 +524,7 @@ void cWebAdmin::OnRequestFinished(cHTTPConnection & a_Connection, cHTTPRequest &
// Delete any request data assigned to the request: // Delete any request data assigned to the request:
cRequestData * Data = (cRequestData *)(a_Request.GetUserData()); cRequestData * Data = (cRequestData *)(a_Request.GetUserData());
delete Data; delete Data;
Data = NULL;
} }

View File

@ -267,12 +267,12 @@ cWorld::cWorld(const AString & a_WorldName) :
cWorld::~cWorld() cWorld::~cWorld()
{ {
delete m_SimulatorManager; delete m_SimulatorManager; m_SimulatorManager = NULL;
delete m_SandSimulator; delete m_SandSimulator; m_SandSimulator = NULL;
delete m_WaterSimulator; delete m_WaterSimulator; m_WaterSimulator = NULL;
delete m_LavaSimulator; delete m_LavaSimulator; m_LavaSimulator = NULL;
delete m_FireSimulator; delete m_FireSimulator; m_FireSimulator = NULL;
delete m_RedstoneSimulator; delete m_RedstoneSimulator; m_RedstoneSimulator = NULL;
UnloadUnusedChunks(); UnloadUnusedChunks();
@ -2972,11 +2972,13 @@ int cWorld::SpawnMobFinalize(cMonster * a_Monster)
if (cPluginManager::Get()->CallHookSpawningMonster(*this, *a_Monster)) if (cPluginManager::Get()->CallHookSpawningMonster(*this, *a_Monster))
{ {
delete a_Monster; delete a_Monster;
a_Monster = NULL;
return -1; return -1;
} }
if (!a_Monster->Initialize(*this)) if (!a_Monster->Initialize(*this))
{ {
delete a_Monster; delete a_Monster;
a_Monster = NULL;
return -1; return -1;
} }
BroadcastSpawnEntity(*a_Monster); BroadcastSpawnEntity(*a_Monster);
@ -2999,6 +3001,7 @@ int cWorld::CreateProjectile(double a_PosX, double a_PosY, double a_PosZ, cProje
if (!Projectile->Initialize(*this)) if (!Projectile->Initialize(*this))
{ {
delete Projectile; delete Projectile;
Projectile = NULL;
return -1; return -1;
} }
return Projectile->GetUniqueID(); return Projectile->GetUniqueID();

View File

@ -830,6 +830,7 @@ private:
virtual ~cScheduledTask() virtual ~cScheduledTask()
{ {
delete m_Task; delete m_Task;
m_Task = NULL;
} }
}; };

View File

@ -473,6 +473,7 @@ cWSSCompact::cPAKFile::cPAKFile(const AString & a_FileName, int a_LayerX, int a_
{ {
LOGERROR("ERROR READING %s FROM FILE %s (line %d); file offset %d", "Header", m_FileName.c_str(), __LINE__, f.Tell()); LOGERROR("ERROR READING %s FROM FILE %s (line %d); file offset %d", "Header", m_FileName.c_str(), __LINE__, f.Tell());
delete Header; delete Header;
Header = NULL;
return; return;
} }
m_ChunkHeaders.push_back(Header); m_ChunkHeaders.push_back(Header);