aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorFilippos Karapetis2011-01-15 23:55:35 +0000
committerFilippos Karapetis2011-01-15 23:55:35 +0000
commit0309f365523cd43d0a8d27f921d70d20a4deae7b (patch)
tree64b655fe50ad9f6010f24fd4a5b574be71a32d75 /engines
parent09c35e99b8d06a883eeab10a4f3955c0a3777973 (diff)
downloadscummvm-rg350-0309f365523cd43d0a8d27f921d70d20a4deae7b.tar.gz
scummvm-rg350-0309f365523cd43d0a8d27f921d70d20a4deae7b.tar.bz2
scummvm-rg350-0309f365523cd43d0a8d27f921d70d20a4deae7b.zip
SCI: Plugged 2 memory leaks, reported by digitall
- Plugged 2 memory leaks in the SCI0 menu code (the lists of menu and submenu entries) - Got rid of the _listCount variable svn-id: r55254
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/graphics/menu.cpp23
-rw-r--r--engines/sci/graphics/menu.h1
2 files changed, 15 insertions, 9 deletions
diff --git a/engines/sci/graphics/menu.cpp b/engines/sci/graphics/menu.cpp
index c597d4aca8..3b9119c52f 100644
--- a/engines/sci/graphics/menu.cpp
+++ b/engines/sci/graphics/menu.cpp
@@ -54,14 +54,20 @@ GfxMenu::GfxMenu(EventManager *event, SegManager *segMan, GfxPorts *ports, GfxPa
}
GfxMenu::~GfxMenu() {
- // TODO: deallocate _list and _itemList
- reset();
+ for (GuiMenuItemList::iterator itemIter = _itemList.begin(); itemIter != _itemList.end(); ++itemIter)
+ delete *itemIter;
+
+ _itemList.clear();
+
+ for (GuiMenuList::iterator menuIter = _list.begin(); menuIter != _list.end(); ++menuIter)
+ delete *menuIter;
+
+ _list.clear();
}
void GfxMenu::reset() {
_list.clear();
_itemList.clear();
- _listCount = 0;
// We actually set active item in here and remember last selection of the
// user. Sierra SCI always defaulted to first item every time menu was
@@ -81,15 +87,16 @@ void GfxMenu::kernelAddEntry(Common::String title, Common::String content, reg_t
const char *tempPtr;
// Sierra SCI starts with id 1, so we do so as well
- _listCount++;
- menuEntry = new GuiMenuEntry(_listCount);
+ menuEntry = new GuiMenuEntry(_list.size() + 1);
menuEntry->text = title;
_list.push_back(menuEntry);
curPos = 0;
+ uint16 listSize = _list.size();
+
do {
itemCount++;
- itemEntry = new GuiMenuItemEntry(_listCount, itemCount);
+ itemEntry = new GuiMenuItemEntry(listSize, itemCount);
beginPos = curPos;
@@ -498,10 +505,10 @@ GuiMenuItemEntry *GfxMenu::interactiveGetItem(uint16 menuId, uint16 itemId, bool
GuiMenuItemEntry *lastItemEntry = NULL;
// Fixup menuId if needed
- if (menuId > _listCount)
+ if (menuId > _list.size())
menuId = 1;
if (menuId == 0)
- menuId = _listCount;
+ menuId = _list.size();
while (itemIterator != itemEnd) {
itemEntry = *itemIterator;
if (itemEntry->menuId == menuId) {
diff --git a/engines/sci/graphics/menu.h b/engines/sci/graphics/menu.h
index 9a14d4c64a..a6ac4d1d4c 100644
--- a/engines/sci/graphics/menu.h
+++ b/engines/sci/graphics/menu.h
@@ -119,7 +119,6 @@ private:
GfxScreen *_screen;
GfxCursor *_cursor;
- uint16 _listCount;
GuiMenuList _list;
GuiMenuItemList _itemList;