[Scummvm-git-logs] scummvm master -> c6c56efc4af184e37011c3d07ba4677c5bbc2b3e

rvanlaar noreply at scummvm.org
Thu Sep 22 21:36:49 UTC 2022


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
c6c56efc4a DIRECTOR: Fix mac memory leaks


Commit: c6c56efc4af184e37011c3d07ba4677c5bbc2b3e
    https://github.com/scummvm/scummvm/commit/c6c56efc4af184e37011c3d07ba4677c5bbc2b3e
Author: Roland van Laar (roland at rolandvanlaar.nl)
Date: 2022-09-22T23:36:39+02:00

Commit Message:
DIRECTOR: Fix mac memory leaks

There are two types of memory types of leaks fixed that both deal with
mac resource files.

First one, opened resource files weren't always deleted when cleaning up
or on failure of opening.

Second one, the cursors are read from streams of resource files.
Those streams are marked as disposable. They are only disposed of when
delete is called on them.

Changed paths:
    engines/director/cursor.cpp
    engines/director/lingo/lingo-builtins.cpp


diff --git a/engines/director/cursor.cpp b/engines/director/cursor.cpp
index 91208ff8e66..bbc68639be9 100644
--- a/engines/director/cursor.cpp
+++ b/engines/director/cursor.cpp
@@ -176,9 +176,8 @@ void Cursor::readFromResource(Datum resourceId) {
 		bool readSuccessful = false;
 
 		for (Common::HashMap<Common::String, Archive *, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo>::iterator it = g_director->_openResFiles.begin(); it != g_director->_openResFiles.end(); ++it) {
-			Common::SeekableReadStreamEndian *cursorStream = nullptr;
 			MacArchive *arch = (MacArchive *)it->_value;
-
+			Common::SeekableReadStreamEndian *cursorStream = nullptr;
 			if (arch->hasResource(MKTAG('C', 'U', 'R', 'S'), resourceId.asInt()))
 				cursorStream = arch->getResource(MKTAG('C', 'U', 'R', 'S'), resourceId.asInt());
 
@@ -191,8 +190,10 @@ void Cursor::readFromResource(Datum resourceId) {
 				readSuccessful = true;
 
 				resetCursor(Graphics::kMacCursorCustom, false, resourceId);
+				delete cursorStream;
 				break;
 			}
+			delete cursorStream;
 		}
 
 		// TODO: figure out where to read custom cursor in windows platform
diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp
index 203f51b75ad..0c46117c560 100644
--- a/engines/director/lingo/lingo-builtins.cpp
+++ b/engines/director/lingo/lingo-builtins.cpp
@@ -1059,13 +1059,22 @@ void LB::b_closeDA(int nargs) {
 
 void LB::b_closeResFile(int nargs) {
 	if (nargs == 0) { // Close all res files
+		for (Common::HashMap<Common::String, Archive *, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo>::iterator
+				it = g_director->_openResFiles.begin(); it != g_director->_openResFiles.end(); ++it) {
+			delete it->_value;
+		}
 		g_director->_openResFiles.clear();
 		return;
 	}
+
 	Datum d = g_lingo->pop();
 	Common::String resFileName = g_director->getCurrentWindow()->getCurrentPath() + d.asString();
 
-	g_director->_openResFiles.erase(resFileName);
+	if (g_director->_openResFiles.contains(resFileName)) {
+		auto archive = g_director->_openResFiles.getVal(resFileName);
+		delete archive;
+		g_director->_openResFiles.erase(resFileName);
+	}
 }
 
 void LB::b_closeXlib(int nargs) {
@@ -1145,6 +1154,8 @@ void LB::b_openResFile(int nargs) {
 
 		if (resFile->openFile(pathMakeRelative(resPath))) {
 			g_director->_openResFiles.setVal(resPath, resFile);
+		} else {
+			delete resFile;
 		}
 	}
 }
@@ -1179,6 +1190,8 @@ void LB::b_openXlib(int nargs) {
 					g_lingo->openXLib(xlibName, kXObj);
 				}
 				return;
+			} else {
+				delete resFile;
 			}
 		}
 	}




More information about the Scummvm-git-logs mailing list