Remove some redundant explicit NULL checks for pointers before ´delete´ or ´delete[]´ calls since this check is done implicitly when deleting.
Also fixes a memory leak in .reload creature_template command --HG-- branch : trunk
This commit is contained in:
@@ -121,16 +121,11 @@ namespace VMAP
|
||||
//===============================================
|
||||
// delete all internal data structures
|
||||
void VMapFactory::clear()
|
||||
{
|
||||
if(iIgnoreSpellIds)
|
||||
{
|
||||
delete iIgnoreSpellIds;
|
||||
iIgnoreSpellIds = NULL;
|
||||
}
|
||||
if(gVMapManager)
|
||||
{
|
||||
|
||||
delete gVMapManager;
|
||||
gVMapManager = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -795,24 +795,21 @@ bool ChatHandler::HandleReloadCreatureTemplateCommand(const char* args)
|
||||
size_t len = 0;
|
||||
if (const char* temp = fields[9].GetString())
|
||||
{
|
||||
if (cInfo->Name)
|
||||
delete cInfo->Name;
|
||||
delete[] cInfo->Name;
|
||||
len = strlen(temp)+1;
|
||||
const_cast<CreatureInfo*>(cInfo)->Name = new char[len];
|
||||
strncpy(cInfo->Name, temp, len);
|
||||
}
|
||||
if (const char* temp = fields[10].GetString())
|
||||
{
|
||||
if (cInfo->SubName)
|
||||
delete cInfo->SubName;
|
||||
delete[] cInfo->SubName;
|
||||
len = strlen(temp)+1;
|
||||
const_cast<CreatureInfo*>(cInfo)->SubName = new char[len];
|
||||
strncpy(cInfo->SubName, temp, len);
|
||||
}
|
||||
if (const char* temp = fields[11].GetString())
|
||||
{
|
||||
if (cInfo->IconName)
|
||||
delete cInfo->IconName;
|
||||
delete[] cInfo->IconName;
|
||||
len = strlen(temp)+1;
|
||||
const_cast<CreatureInfo*>(cInfo)->IconName = new char[len];
|
||||
strncpy(cInfo->IconName, temp, len);
|
||||
@@ -871,8 +868,7 @@ bool ChatHandler::HandleReloadCreatureTemplateCommand(const char* args)
|
||||
const_cast<CreatureInfo*>(cInfo)->maxgold = fields[63].GetUInt32();
|
||||
if (const char* temp = fields[64].GetString())
|
||||
{
|
||||
if (cInfo->AIName)
|
||||
delete cInfo->AIName;
|
||||
delete[] cInfo->AIName;
|
||||
len = strlen(temp)+1;
|
||||
const_cast<CreatureInfo*>(cInfo)->AIName = new char[len];
|
||||
strncpy(const_cast<char*>(cInfo->AIName), temp, len);
|
||||
|
||||
@@ -235,7 +235,7 @@ inline void LoadDBC(uint32& availableDbcLocales,barGoLink& bar, StoreProblemList
|
||||
else
|
||||
errlist.push_back(dbc_filename);
|
||||
}
|
||||
if (sql)
|
||||
|
||||
delete sql;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,7 @@ LFGQueue::~LFGQueue()
|
||||
|
||||
void LFGQueue::AddToQueue(uint64 guid, LfgQueueInfo* pqInfo)
|
||||
{
|
||||
if (LfgQueueInfo* qInfo = m_LfgQueue[guid])
|
||||
delete qInfo;
|
||||
delete m_LfgQueue[guid];
|
||||
m_LfgQueue[guid] = pqInfo;
|
||||
// ATM will only add it to the queue... No find group implementation... yet (on purpose)
|
||||
}
|
||||
|
||||
@@ -171,11 +171,8 @@ Creature::~Creature()
|
||||
{
|
||||
m_vendorItemCounts.clear();
|
||||
|
||||
if (i_AI)
|
||||
{
|
||||
delete i_AI;
|
||||
i_AI = NULL;
|
||||
}
|
||||
|
||||
//if (m_uint32Values)
|
||||
// sLog.outError("Deconstruct Creature Entry = %u", GetEntry());
|
||||
@@ -721,7 +718,7 @@ bool Creature::AIM_Initialize(CreatureAI* ai)
|
||||
Motion_Initialize();
|
||||
|
||||
i_AI = ai ? ai : FactorySelector::selectAI(this);
|
||||
if (oldAI) delete oldAI;
|
||||
delete oldAI;
|
||||
IsAIEnabled = true;
|
||||
i_AI->InitializeAI();
|
||||
return true;
|
||||
|
||||
@@ -117,12 +117,9 @@ bool Bag::LoadFromDB(uint32 guid, uint64 owner_guid, QueryResult_AutoPtr result)
|
||||
for (uint8 i = 0; i < MAX_BAG_SIZE; ++i)
|
||||
{
|
||||
SetUInt64Value(CONTAINER_FIELD_SLOT_1 + (i*2), 0);
|
||||
if (m_bagslot[i])
|
||||
{
|
||||
delete m_bagslot[i];
|
||||
m_bagslot[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -113,13 +113,9 @@ Object::~Object()
|
||||
ObjectAccessor::Instance().RemoveUpdateObject(this);
|
||||
}
|
||||
|
||||
if (m_uint32Values)
|
||||
{
|
||||
//DEBUG_LOG("Object desctr 1 check (%p)",(void*)this);
|
||||
delete [] m_uint32Values;
|
||||
delete [] m_uint32Values_mirror;
|
||||
//DEBUG_LOG("Object desctr 2 check (%p)",(void*)this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Object::_InitValues()
|
||||
|
||||
@@ -32,7 +32,6 @@ class UpdateMask
|
||||
|
||||
~UpdateMask()
|
||||
{
|
||||
if (mUpdateMask)
|
||||
delete [] mUpdateMask;
|
||||
}
|
||||
|
||||
@@ -58,7 +57,6 @@ class UpdateMask
|
||||
|
||||
void SetCount (uint32 valuesCount)
|
||||
{
|
||||
if (mUpdateMask)
|
||||
delete [] mUpdateMask;
|
||||
|
||||
mCount = valuesCount;
|
||||
|
||||
@@ -324,9 +324,7 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petentry, uint32 petnumber, bool c
|
||||
|
||||
if (result)
|
||||
{
|
||||
if (m_declinedname)
|
||||
delete m_declinedname;
|
||||
|
||||
m_declinedname = new DeclinedName;
|
||||
Field *fields2 = result->Fetch();
|
||||
for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
|
||||
|
||||
@@ -514,10 +514,7 @@ Player::~Player ()
|
||||
|
||||
// Note: buy back item already deleted from DB when player was saved
|
||||
for (uint8 i = 0; i < PLAYER_SLOTS_COUNT; ++i)
|
||||
{
|
||||
if (m_items[i])
|
||||
delete m_items[i];
|
||||
}
|
||||
|
||||
for (PlayerSpellMap::const_iterator itr = m_spells.begin(); itr != m_spells.end(); ++itr)
|
||||
delete itr->second;
|
||||
@@ -539,7 +536,6 @@ Player::~Player ()
|
||||
delete PlayerTalkClass;
|
||||
|
||||
for (size_t x = 0; x < ItemSetEff.size(); x++)
|
||||
if (ItemSetEff[x])
|
||||
delete ItemSetEff[x];
|
||||
|
||||
delete m_declinedname;
|
||||
@@ -15565,9 +15561,7 @@ void Player::_LoadDeclinedNames(QueryResult_AutoPtr result)
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
if (m_declinedname)
|
||||
delete m_declinedname;
|
||||
|
||||
m_declinedname = new DeclinedName;
|
||||
Field *fields = result->Fetch();
|
||||
for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
|
||||
@@ -15817,12 +15811,9 @@ bool Player::LoadFromDB(uint32 guid, SqlQueryHolder *holder)
|
||||
SetUInt64Value(PLAYER_FIELD_INV_SLOT_HEAD + (slot * 2), 0);
|
||||
SetVisibleItemSlot(slot, NULL);
|
||||
|
||||
if (m_items[slot])
|
||||
{
|
||||
delete m_items[slot];
|
||||
m_items[slot] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
sLog.outDebug("Load Basic value of player %s is: ", m_name.c_str());
|
||||
outDebugValues();
|
||||
|
||||
@@ -201,9 +201,7 @@ Unit::~Unit()
|
||||
RemoveAllDynObjects();
|
||||
_DeleteRemovedAuras();
|
||||
|
||||
if (m_charmInfo)
|
||||
delete m_charmInfo;
|
||||
if (m_vehicleKit)
|
||||
delete m_vehicleKit;
|
||||
|
||||
assert(!m_attacking);
|
||||
@@ -13297,7 +13295,6 @@ void Unit::UpdateCharmAI()
|
||||
{
|
||||
if (!isCharmed())
|
||||
{
|
||||
if (i_AI)
|
||||
delete i_AI;
|
||||
i_AI = i_disabledAI;
|
||||
i_disabledAI = NULL;
|
||||
|
||||
@@ -3419,7 +3419,7 @@ void ObjectMgr::LoadGuilds()
|
||||
!newGuild->LoadMembersFromDB(guildMembersResult) ||
|
||||
!newGuild->LoadBankRightsFromDB(guildBankTabRightsResult) ||
|
||||
!newGuild->CheckGuildStructure()
|
||||
)
|
||||
)
|
||||
{
|
||||
newGuild->Disband();
|
||||
delete newGuild;
|
||||
|
||||
@@ -79,7 +79,6 @@ Group::~Group()
|
||||
itr2->second.save->RemoveGroup(this);
|
||||
|
||||
// Sub group counters clean up
|
||||
if (m_subGroupsCounts)
|
||||
delete[] m_subGroupsCounts;
|
||||
}
|
||||
|
||||
|
||||
@@ -1241,11 +1241,11 @@ bool GridMap::loadData(char *filename)
|
||||
|
||||
void GridMap::unloadData()
|
||||
{
|
||||
if (m_area_map) delete[] m_area_map;
|
||||
if (m_V9) delete[] m_V9;
|
||||
if (m_V8) delete[] m_V8;
|
||||
if (m_liquid_type) delete[] m_liquid_type;
|
||||
if (m_liquid_map) delete[] m_liquid_map;
|
||||
delete[] m_area_map;
|
||||
delete[] m_V9;
|
||||
delete[] m_V8;
|
||||
delete[] m_liquid_type;
|
||||
delete[] m_liquid_map;
|
||||
m_area_map = NULL;
|
||||
m_V9 = NULL;
|
||||
m_V8 = NULL;
|
||||
@@ -2350,11 +2350,8 @@ InstanceMap::InstanceMap(uint32 id, time_t expiry, uint32 InstanceId, uint8 Spaw
|
||||
|
||||
InstanceMap::~InstanceMap()
|
||||
{
|
||||
if (i_data)
|
||||
{
|
||||
delete i_data;
|
||||
i_data = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void InstanceMap::InitVisibilityDistance()
|
||||
|
||||
@@ -120,7 +120,6 @@ m_LastPingTime(ACE_Time_Value::zero)
|
||||
|
||||
WorldSocket::~WorldSocket (void)
|
||||
{
|
||||
if (m_RecvWPct)
|
||||
delete m_RecvWPct;
|
||||
|
||||
if (m_OutBuffer)
|
||||
|
||||
@@ -84,7 +84,6 @@ class ReactorRunnable : protected ACE_Task_Base
|
||||
Stop();
|
||||
Wait();
|
||||
|
||||
if (m_Reactor)
|
||||
delete m_Reactor;
|
||||
}
|
||||
|
||||
@@ -220,10 +219,7 @@ WorldSocketMgr::WorldSocketMgr() :
|
||||
|
||||
WorldSocketMgr::~WorldSocketMgr()
|
||||
{
|
||||
if (m_NetThreads)
|
||||
delete [] m_NetThreads;
|
||||
|
||||
if (m_Acceptor)
|
||||
delete m_Acceptor;
|
||||
}
|
||||
|
||||
|
||||
@@ -387,7 +387,6 @@ AuraEffect::AuraEffect(Aura * base, uint8 effIndex, int32 *baseAmount, Unit * ca
|
||||
|
||||
AuraEffect::~AuraEffect()
|
||||
{
|
||||
if (m_spellmod)
|
||||
delete m_spellmod;
|
||||
}
|
||||
|
||||
|
||||
@@ -342,7 +342,6 @@ Aura::~Aura()
|
||||
{
|
||||
// free effects memory
|
||||
for (uint8 i = 0 ; i < MAX_SPELL_EFFECTS; ++i)
|
||||
if (m_effects[i])
|
||||
delete m_effects[i];
|
||||
|
||||
assert(m_applications.empty());
|
||||
|
||||
@@ -142,7 +142,7 @@ World::~World()
|
||||
|
||||
VMAP::VMapFactory::clear();
|
||||
|
||||
if (m_resultQueue) delete m_resultQueue;
|
||||
delete m_resultQueue;
|
||||
|
||||
//TODO free addSessQueue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user