Attempt to fix some minor memory leaks
authorPerttu Ahola <celeron55@gmail.com>
Tue, 20 Mar 2012 15:55:34 +0000 (17:55 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Tue, 20 Mar 2012 15:55:34 +0000 (17:55 +0200)
src/connection.cpp
src/itemdef.cpp

index 31aa9330751b81afbadc343c6daead026725a5e8..127cabdc51ead787e586cb7069b662fca840370c 100644 (file)
@@ -537,6 +537,14 @@ Connection::Connection(u32 protocol_id, u32 max_packet_size, float timeout,
 Connection::~Connection()
 {
        stop();
+       // Delete peers
+       for(core::map<u16, Peer*>::Iterator
+                       j = m_peers.getIterator();
+                       j.atEnd() == false; j++)
+       {
+               Peer *peer = j.getNode()->getValue();
+               delete peer;
+       }
 }
 
 /* Internal stuff */
index a646134af7aa41c8e95c1f5ed8b1968d49835f1f..934150aa17dac25429f2d624f0f322e69aeeec48 100644 (file)
@@ -290,8 +290,11 @@ public:
                // Ensure that the "" item (the hand) always has ToolCapabilities
                if(def.name == "")
                        assert(def.tool_capabilities != NULL);
-
-               m_item_definitions[def.name] = new ItemDefinition(def);
+               
+               if(m_item_definitions.count(def.name) == 0)
+                       m_item_definitions[def.name] = new ItemDefinition(def);
+               else
+                       *(m_item_definitions[def.name]) = def;
 
                // Remove conflicting alias if it exists
                bool alias_removed = (m_aliases.erase(def.name) != 0);