summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-05-25 02:51:51 +0300
committerAndrei Karas <akaras@inbox.ru>2011-05-25 02:51:51 +0300
commit8d80b897b5863372649de9b5f3c8d7234ae47f58 (patch)
treea109bb1adeee89489113a4637ecd197dae403018 /src
parent1f4032b8de527da72ef4b89371c077eea644fdf2 (diff)
downloadmv-8d80b897b5863372649de9b5f3c8d7234ae47f58.tar.gz
mv-8d80b897b5863372649de9b5f3c8d7234ae47f58.tar.bz2
mv-8d80b897b5863372649de9b5f3c8d7234ae47f58.tar.xz
mv-8d80b897b5863372649de9b5f3c8d7234ae47f58.zip
Fix some memory leaks in being, debugwindow, shortcutwindow, skilldialog, map classes.
Diffstat (limited to 'src')
-rw-r--r--src/being.cpp6
-rw-r--r--src/being.h2
-rw-r--r--src/game.cpp4
-rw-r--r--src/gui/debugwindow.cpp10
-rw-r--r--src/gui/debugwindow.h2
-rw-r--r--src/gui/shortcutwindow.cpp2
-rw-r--r--src/gui/skilldialog.cpp16
-rw-r--r--src/gui/widgets/tabbedarea.cpp18
-rw-r--r--src/gui/widgets/tabbedarea.h2
-rw-r--r--src/map.cpp4
10 files changed, 51 insertions, 15 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 5230edeae..f414400be 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -2220,6 +2220,12 @@ void Being::undressItemById(int id)
}
}
+void Being::clearCache()
+{
+ delete_all(beingInfoCache);
+ beingInfoCache.clear();
+}
+
BeingEquipBackend::BeingEquipBackend(Being *being):
mBeing(being)
{
diff --git a/src/being.h b/src/being.h
index 04cee8bcc..1f0d318f3 100644
--- a/src/being.h
+++ b/src/being.h
@@ -715,6 +715,8 @@ class Being : public ActorSprite, public ConfigListener
void undressItemById(int id);
+ static void clearCache();
+
protected:
/**
* Sets the new path for this being.
diff --git a/src/game.cpp b/src/game.cpp
index d4c26d6e8..850d335e4 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -26,6 +26,7 @@
#include "actorspritemanager.h"
#include "actorsprite.h"
+#include "being.h"
#include "channelmanager.h"
#include "client.h"
#include "commandhandler.h"
@@ -96,6 +97,7 @@
#include "resources/mapreader.h"
#include "resources/resourcemanager.h"
+#include "utils/dtor.h"
#include "utils/gettext.h"
#include "utils/mkdir.h"
@@ -399,6 +401,8 @@ Game::~Game()
del_0(spellShortcut);
del_0(mumbleManager);
+ Being::clearCache();
+
mInstance = 0;
Mana::Event::trigger(CHANNEL_GAME, Mana::Event(EVENT_DESTRUCTED));
diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp
index ecc3ada54..d7cec480a 100644
--- a/src/gui/debugwindow.cpp
+++ b/src/gui/debugwindow.cpp
@@ -80,6 +80,16 @@ DebugWindow::DebugWindow():
loadWindowState();
}
+DebugWindow::~DebugWindow()
+{
+ delete mMapWidget;
+ mMapWidget = 0;
+ delete mTargetWidget;
+ mTargetWidget = 0;
+ delete mNetWidget;
+ mNetWidget = 0;
+}
+
void DebugWindow::logic()
{
if (!isVisible() || !mTabs)
diff --git a/src/gui/debugwindow.h b/src/gui/debugwindow.h
index ae4b1b597..b955209a5 100644
--- a/src/gui/debugwindow.h
+++ b/src/gui/debugwindow.h
@@ -118,6 +118,8 @@ class DebugWindow : public Window
*/
DebugWindow();
+ ~DebugWindow();
+
/**
* Logic (updates components' size and infos)
*/
diff --git a/src/gui/shortcutwindow.cpp b/src/gui/shortcutwindow.cpp
index f9db35ff6..0492afce0 100644
--- a/src/gui/shortcutwindow.cpp
+++ b/src/gui/shortcutwindow.cpp
@@ -131,6 +131,8 @@ ShortcutWindow::ShortcutWindow(const std::string &title, int width, int height)
ShortcutWindow::~ShortcutWindow()
{
+ if (mTabs)
+ mTabs->removeAll();
delete mTabs;
mTabs = 0;
delete mItems;
diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp
index 7163d5285..a164d59d7 100644
--- a/src/gui/skilldialog.cpp
+++ b/src/gui/skilldialog.cpp
@@ -314,21 +314,7 @@ void SkillDialog::update()
void SkillDialog::loadSkills(const std::string &file)
{
- // Fixes issues with removing tabs
- if (mTabs->getSelectedTabIndex() != -1)
- {
- mTabs->setSelectedTab(static_cast<unsigned int>(0));
-
- while (mTabs->getNumberOfTabs() > 0)
- {
- const int idx = mTabs->getNumberOfTabs() - 1;
- Tab *tab = mTabs->getTabByIndex(idx);
- Widget *widget = mTabs->getWidgetByIndex(idx);
- mTabs->removeTab(tab);
- delete tab;
- delete widget;
- }
- }
+ mTabs->removeAll();
delete_all(mSkills);
mSkills.clear();
diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp
index 6c2ef5b25..b20237c1b 100644
--- a/src/gui/widgets/tabbedarea.cpp
+++ b/src/gui/widgets/tabbedarea.cpp
@@ -442,6 +442,24 @@ gcn::Widget *TabbedArea::getWidgetByIndex(int index) const
return mTabs[index].second;
}
+void TabbedArea::removeAll()
+{
+ if (getSelectedTabIndex() != -1)
+ {
+ setSelectedTab(static_cast<unsigned int>(0));
+
+ }
+ while (getNumberOfTabs() > 0)
+ {
+ const int idx = getNumberOfTabs() - 1;
+ gcn::Tab *tab = mTabs[idx].first;
+ Widget *widget = mTabs[idx].second;
+ removeTab(tab);
+ delete tab;
+ delete widget;
+ }
+}
+
/*
void TabbedArea::moveLeft(gcn::Tab *tab)
{
diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h
index dccf72357..d6f0783df 100644
--- a/src/gui/widgets/tabbedarea.h
+++ b/src/gui/widgets/tabbedarea.h
@@ -108,6 +108,8 @@ class TabbedArea : public gcn::TabbedArea, public gcn::WidgetListener
*/
void removeTab(gcn::Tab *tab);
+ void removeAll();
+
/**
* Overload the logic function since it's broken in guichan 0.8.
*/
diff --git a/src/map.cpp b/src/map.cpp
index 93e2acd1a..69963b354 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -1840,6 +1840,10 @@ ObjectsLayer::ObjectsLayer(unsigned width, unsigned height) :
ObjectsLayer::~ObjectsLayer()
{
+ const unsigned size = mWidth * mHeight;
+ for (unsigned f = 0; f < size; f ++)
+ delete mTiles[f];
+
delete [] mTiles;
mTiles = 0;
}