[Scummvm-cvs-logs] SF.net SVN: scummvm:[55254] scummvm/trunk/engines/sci/graphics

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Sun Jan 16 00:55:35 CET 2011


Revision: 55254
          http://scummvm.svn.sourceforge.net/scummvm/?rev=55254&view=rev
Author:   thebluegr
Date:     2011-01-15 23:55:35 +0000 (Sat, 15 Jan 2011)

Log Message:
-----------
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

Modified Paths:
--------------
    scummvm/trunk/engines/sci/graphics/menu.cpp
    scummvm/trunk/engines/sci/graphics/menu.h

Modified: scummvm/trunk/engines/sci/graphics/menu.cpp
===================================================================
--- scummvm/trunk/engines/sci/graphics/menu.cpp	2011-01-15 19:11:53 UTC (rev 55253)
+++ scummvm/trunk/engines/sci/graphics/menu.cpp	2011-01-15 23:55:35 UTC (rev 55254)
@@ -54,14 +54,20 @@
 }
 
 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 @@
 	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 *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) {

Modified: scummvm/trunk/engines/sci/graphics/menu.h
===================================================================
--- scummvm/trunk/engines/sci/graphics/menu.h	2011-01-15 19:11:53 UTC (rev 55253)
+++ scummvm/trunk/engines/sci/graphics/menu.h	2011-01-15 23:55:35 UTC (rev 55254)
@@ -119,7 +119,6 @@
 	GfxScreen *_screen;
 	GfxCursor *_cursor;
 
-	uint16 _listCount;
 	GuiMenuList _list;
 	GuiMenuItemList _itemList;
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list