Jump to content

[10284][Fix] Memory leaks in Guild.cpp + bank items deletion


Recommended Posts

Posted

  • * What bug does the patch fix? What features does the patch add?
    -Fix some memory leaks in Guild.cpp, precisely in the Disband method.
    -Delete the items that are stored in the guild bank when the guild is deleted.
    * For which repository revision was the patch created?
    10272
    * Is there a thread in the bug report section or at lighthouse? If yes, please add a link to the thread.
    Didn't found any
    * Who has been writing this patch? Please include either forum user names or email addresses.
    porteyoplait (=me)

Compiles right, but needs testing.

Correct me if I'm wrong!

Here is the patch :

diff --git a/src/game/Guild.cpp b/src/game/Guild.cpp
index a89235f..06350a7 100644
--- a/src/game/Guild.cpp
+++ b/src/game/Guild.cpp
@@ -691,7 +691,20 @@ void Guild::Disband()
    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 ?
+    //Free bank tab used memory and delete items stored in them
+    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]) {
+                pItem->DeleteFromDB();
+                delete pItem;
+            } 
+        }
+        delete m_TabListMap[i]; 
+    }
+
+    for (; i < m_TabListMap.size(); ++i)
+        delete m_TabListMap[i];
    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);

Thanks for future answers :)

Posted

Thank you for finding this probems with items. But same porblem exist also at guild unload at server shutdown.

Ofc, memory free in any cases at shutdown, but different memory leak detectors will triggering at this memory as lost.

So i plan rewrite your patch for use same code (without DB deleting) for ~Guid and possible remove m_PurchasedTabs...

About used code itself: items in guild bank considered as in world, so before deletion its must be moved from world

pItem->RemoveFromWorld();

Or you can have problems with not finished update packets for clients /etc

Posted

Ok, thanks!

I was asking myself if was necessary to do the same in ~Guild.

Thanks for the tip with RemoveFromWorld() too. I've never really known what this function was doing. I will remember :)

×
×
  • 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