Jump to content

A few memory leaks in Guild.cpp

Guest Toinan67

Recommended Posts


I (maybe I'm wrong) noticed some mem leaks in Guild.cpp.

   Field *fields = result->Fetch();
   uint8 TabId = fields[0].GetUInt8();

   GuildBankTab *NewTab = new GuildBankTab;
   memset(NewTab->Slots, 0, GUILD_BANK_MAX_SLOTS * sizeof(Item*));

   NewTab->Name = fields[1].GetCppString();
   NewTab->Icon = fields[2].GetCppString();
   NewTab->Text = fields[3].GetCppString();

   m_TabListMap[TabId] = NewTab;
} while (result->NextRow());

You can see the new GuildBankTab.

And, when the guild is disbanded :

void Guild::Disband()
   BroadcastEvent(GE_DISBANDED, 0, 0, "", "", "");

   while (!members.empty())
       MemberList::const_iterator itr = members.begin();
       DelMember(MAKE_NEW_GUID(itr->first, 0, HIGHGUID_PLAYER), true);

   CharacterDatabase.PExecute("DELETE FROM guild WHERE guildid = '%u'", m_Id);
   CharacterDatabase.PExecute("DELETE FROM guild_rank WHERE guildid = '%u'", m_Id);
   CharacterDatabase.PExecute("DELETE FROM guild_bank_tab WHERE guildid = '%u'", m_Id);
   // TODO item_instance should be deleted ?
   CharacterDatabase.PExecute("DELETE FROM guild_bank_item WHERE guildid = '%u'", m_Id);
   CharacterDatabase.PExecute("DELETE FROM guild_bank_right WHERE guildid = '%u'", m_Id);
   CharacterDatabase.PExecute("DELETE FROM guild_bank_eventlog WHERE guildid = '%u'", m_Id);
   CharacterDatabase.PExecute("DELETE FROM guild_eventlog WHERE guildid = '%u'", m_Id);

Nothing is released. Same things for the items in the guild bank.

So maybe something like this would be nice :

uint8 i = 0;
for (i = 0; i < m_PurchasedTabs; ++i) {
   for (uint8 j = 0; j < GUILD_BANK_MAX_SLOTS; ++j) {
       if (Item* pItem = m_TabListMap[i]->Slots[j]) {
           delete pItem;
   delete m_TabListMap[i]; 

for (; i < m_TabListMap.size(); ++i)
   delete m_TabListMap[i];

(Placed somewhere in Guild :: Disband)

This would also permit to delete the items from the DB (delete from item_instance).

What do you think about it?

It's just a question actually, not sure at all if I'm right :S

Link to comment
Share on other sites

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use