From 04e4f0da4b6242f39d09794edad394587ddea620 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 16 Jul 2010 23:34:17 +0300 Subject: Fix memory corruption in chat on exit. Signed-off-by: Jared Adams --- src/gui/chat.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src/gui/chat.cpp') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index d53bcf0a..f87a8a3d 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -117,7 +117,7 @@ ChatWindow::~ChatWindow() { config.setValue("ReturnToggles", mReturnToggles); delete mRecorder; - delete_all(mWhispers); + removeAllWhispers(); delete mItemLinkHandler; } @@ -233,10 +233,6 @@ bool ChatWindow::isInputFocused() const void ChatWindow::removeTab(ChatTab *tab) { - // Prevent removal of the local chat tab - if (tab == localChatTab) - return; - mChatTabs->removeTab(tab); } @@ -258,6 +254,25 @@ void ChatWindow::removeWhisper(const std::string &nick) mWhispers.erase(tempNick); } +void ChatWindow::removeAllWhispers() +{ + TabMap::iterator iter; + std::list tabs; + + for (iter = mWhispers.begin(); iter != mWhispers.end(); ++iter) + { + tabs.push_back(iter->second); + } + + for (std::list::iterator it = tabs.begin(); + it != tabs.end(); ++it) + { + delete *it; + } + + mWhispers.clear(); +} + void ChatWindow::chatInput(const std::string &msg) { ChatTab *tab = getFocused(); -- cgit v1.2.3-70-g09d2