[Scummvm-cvs-logs] SF.net SVN: scummvm:[49116] scummvm/trunk/common

jvprat at users.sourceforge.net jvprat at users.sourceforge.net
Thu May 20 15:46:18 CEST 2010


Revision: 49116
          http://scummvm.svn.sourceforge.net/scummvm/?rev=49116&view=rev
Author:   jvprat
Date:     2010-05-20 13:46:18 +0000 (Thu, 20 May 2010)

Log Message:
-----------
Make the MacResManager opening more robust to failed tries and plug its memory leaks

Modified Paths:
--------------
    scummvm/trunk/common/macresman.cpp
    scummvm/trunk/common/macresman.h

Modified: scummvm/trunk/common/macresman.cpp
===================================================================
--- scummvm/trunk/common/macresman.cpp	2010-05-20 10:36:54 UTC (rev 49115)
+++ scummvm/trunk/common/macresman.cpp	2010-05-20 13:46:18 UTC (rev 49116)
@@ -110,6 +110,7 @@
 		_baseFileName = filename;
 		return true;
 	}
+	delete macResForkRawStream;
 #endif
 
 	Common::File *file = new Common::File();
@@ -119,18 +120,21 @@
 		_baseFileName = filename;
 		return true;
 	}
+	file->close();
 
 	// Check .bin too
 	if (file->open(filename + ".bin") && loadFromMacBinary(*file)) {
 		_baseFileName = filename;
 		return true;
 	}
-		
+	file->close();
+
 	// Maybe we have a dumped fork?
 	if (file->open(filename + ".rsrc") && loadFromRawFork(*file)) {
 		_baseFileName = filename;
 		return true;
 	}
+	file->close();
 
 	// Fine, what about just the data fork?
 	if (file->open(filename)) {
@@ -138,13 +142,15 @@
 
 		if (isMacBinary(*file)) {
 			file->seek(0, SEEK_SET);
-			loadFromMacBinary(*file);
-		} else {
-			_stream = file;
+			if (loadFromMacBinary(*file))
+				return true;
 		}
+
+		file->seek(0, SEEK_SET);
+		_stream = file;
 		return true;
 	}
-		
+
 	delete file;
 
 	// The file doesn't exist
@@ -163,39 +169,56 @@
 		_baseFileName = filename;
 		return true;
 	}
+	delete macResForkRawStream;
 #endif
 
 	// First, let's try to see if the Mac converted name exists
 	Common::FSNode fsNode = path.getChild("._" + filename);
-	if (fsNode.exists() && !fsNode.isDirectory() && loadFromAppleDouble(*fsNode.createReadStream())) {
-		_baseFileName = filename;
-		return true;
+	if (fsNode.exists() && !fsNode.isDirectory()) {
+		SeekableReadStream *stream = fsNode.createReadStream();
+		if (loadFromAppleDouble(*stream)) {
+			_baseFileName = filename;
+			return true;
+		}
+		delete stream;
 	}
 
 	// Check .bin too
 	fsNode = path.getChild(filename + ".bin");
-	if (fsNode.exists() && !fsNode.isDirectory() && loadFromMacBinary(*fsNode.createReadStream())) {
-		_baseFileName = filename;
-		return true;
+	if (fsNode.exists() && !fsNode.isDirectory()) {
+		SeekableReadStream *stream = fsNode.createReadStream();
+		if (loadFromMacBinary(*stream)) {
+			_baseFileName = filename;
+			return true;
+		}
+		delete stream;
 	}
-		
+
 	// Maybe we have a dumped fork?
 	fsNode = path.getChild(filename + ".rsrc");
-	if (fsNode.exists() && !fsNode.isDirectory() && loadFromRawFork(*fsNode.createReadStream())) {
-		_baseFileName = filename;
-		return true;
+	if (fsNode.exists() && !fsNode.isDirectory()) {
+		SeekableReadStream *stream = fsNode.createReadStream();
+		if (loadFromRawFork(*stream)) {
+			_baseFileName = filename;
+			return true;
+		}
+		delete stream;
 	}
 
 	// Fine, what about just the data fork?
 	fsNode = path.getChild(filename);
 	if (fsNode.exists() && !fsNode.isDirectory()) {
+		SeekableReadStream *stream = fsNode.createReadStream();
 		_baseFileName = filename;
 
-		if (isMacBinary(*fsNode.createReadStream())) {
-			loadFromMacBinary(*fsNode.createReadStream());
-		} else {
-			_stream = fsNode.createReadStream();
+		if (isMacBinary(*stream)) {
+			stream->seek(0, SEEK_SET);
+			if (loadFromMacBinary(*stream))
+				return true;
 		}
+
+		stream->seek(0, SEEK_SET);
+		_stream = stream;
 		return true;
 	}
 
@@ -313,7 +336,7 @@
 
 	debug(7, "got header: data %d [%d] map %d [%d]",
 		_dataOffset, _dataLength, _mapOffset, _mapLength);
-		
+
 	_stream = &stream;
 
 	readMap();

Modified: scummvm/trunk/common/macresman.h
===================================================================
--- scummvm/trunk/common/macresman.h	2010-05-20 10:36:54 UTC (rev 49115)
+++ scummvm/trunk/common/macresman.h	2010-05-20 13:46:18 UTC (rev 49116)
@@ -45,7 +45,7 @@
 public:
 	MacResManager();
 	~MacResManager();
-	
+
 	bool open(Common::String filename);
 	bool open(Common::FSNode path, Common::String filename);
 	void close();
@@ -53,7 +53,7 @@
 	bool hasDataFork();
 	bool hasResFork();
 
-	bool isMacBinary(Common::SeekableReadStream &stream);
+	static bool isMacBinary(Common::SeekableReadStream &stream);
 
 	/**
 	 * Read resource from the Mac Binary file
@@ -76,7 +76,7 @@
 	bool getResForkMD5(char *md5str, uint32 length);
 
 	Common::String getBaseFileName() { return _baseFileName; }
-	
+
 	/**
 	 * Convert cursor from crsr format to format suitable for feeding to CursorMan
 	 * @param data Pointer to the cursor data
@@ -125,7 +125,7 @@
 	} _mode;
 
 	void readMap();
-	
+
 	struct ResMap {
 		uint16 resAttr;
 		uint16 typeOffset;
@@ -148,7 +148,7 @@
 	};
 
 	typedef Resource *ResPtr;
-	
+
 	int32 _resForkOffset;
 	uint32 _resForkSize;
 


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