aboutsummaryrefslogtreecommitdiff
path: root/common/macresman.cpp
diff options
context:
space:
mode:
authorJordi Vilalta Prat2010-05-20 13:46:18 +0000
committerJordi Vilalta Prat2010-05-20 13:46:18 +0000
commit474b804e33aec7d0aa9600fa6b210e50c0d13c85 (patch)
treec243efde22d18eed14c80b120bd5acb2fb3d9088 /common/macresman.cpp
parent23eae4e139507f31bc81f4896b71814f9db860de (diff)
downloadscummvm-rg350-474b804e33aec7d0aa9600fa6b210e50c0d13c85.tar.gz
scummvm-rg350-474b804e33aec7d0aa9600fa6b210e50c0d13c85.tar.bz2
scummvm-rg350-474b804e33aec7d0aa9600fa6b210e50c0d13c85.zip
Make the MacResManager opening more robust to failed tries and plug its memory leaks
svn-id: r49116
Diffstat (limited to 'common/macresman.cpp')
-rw-r--r--common/macresman.cpp63
1 files changed, 43 insertions, 20 deletions
diff --git a/common/macresman.cpp b/common/macresman.cpp
index cb3f1c5b8a..de78cedf61 100644
--- a/common/macresman.cpp
+++ b/common/macresman.cpp
@@ -110,6 +110,7 @@ bool MacResManager::open(Common::String filename) {
_baseFileName = filename;
return true;
}
+ delete macResForkRawStream;
#endif
Common::File *file = new Common::File();
@@ -119,18 +120,21 @@ bool MacResManager::open(Common::String filename) {
_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 @@ bool MacResManager::open(Common::String filename) {
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 @@ bool MacResManager::open(Common::FSNode path, Common::String filename) {
_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 @@ bool MacResManager::load(Common::SeekableReadStream &stream) {
debug(7, "got header: data %d [%d] map %d [%d]",
_dataOffset, _dataLength, _mapOffset, _mapLength);
-
+
_stream = &stream;
readMap();