From c0530921ffac89c2249500ba0a1bddd9d288cfbe Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Tue, 20 Mar 2012 17:55:34 +0200 Subject: [PATCH] Attempt to fix some minor memory leaks --- src/connection.cpp | 8 ++++++++ src/itemdef.cpp | 7 +++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/connection.cpp b/src/connection.cpp index 31aa9330..127cabdc 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -537,6 +537,14 @@ Connection::Connection(u32 protocol_id, u32 max_packet_size, float timeout, Connection::~Connection() { stop(); + // Delete peers + for(core::map::Iterator + j = m_peers.getIterator(); + j.atEnd() == false; j++) + { + Peer *peer = j.getNode()->getValue(); + delete peer; + } } /* Internal stuff */ diff --git a/src/itemdef.cpp b/src/itemdef.cpp index a646134a..934150aa 100644 --- a/src/itemdef.cpp +++ b/src/itemdef.cpp @@ -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); -- 2.30.2