aboutsummaryrefslogtreecommitdiff
path: root/engines/sci
diff options
context:
space:
mode:
authorMax Horn2010-02-17 23:36:50 +0000
committerMax Horn2010-02-17 23:36:50 +0000
commit26b7f0bbb95dad5fc05fc5aec8d675ab7fab9041 (patch)
tree99d66f180511a7b182b2d36b3c2460d8edc98799 /engines/sci
parent3452f5ea2d95e7ff477557a49b89e15c07351bbe (diff)
downloadscummvm-rg350-26b7f0bbb95dad5fc05fc5aec8d675ab7fab9041.tar.gz
scummvm-rg350-26b7f0bbb95dad5fc05fc5aec8d675ab7fab9041.tar.bz2
scummvm-rg350-26b7f0bbb95dad5fc05fc5aec8d675ab7fab9041.zip
SCI: Remove hack in convertSierraGameId which caused a memory leak
svn-id: r48083
Diffstat (limited to 'engines/sci')
-rw-r--r--engines/sci/detection.cpp13
-rw-r--r--engines/sci/engine/game.cpp5
-rw-r--r--engines/sci/engine/vm.h2
3 files changed, 12 insertions, 8 deletions
diff --git a/engines/sci/detection.cpp b/engines/sci/detection.cpp
index d44835c8c4..62099c1b6b 100644
--- a/engines/sci/detection.cpp
+++ b/engines/sci/detection.cpp
@@ -121,7 +121,7 @@ static const PlainGameDescriptor SciGameTitles[] = {
/**
* The fallback game descriptor used by the SCI engine's fallbackDetector.
- * Contents of this struct are to be overwritten by the fallbackDetector.
+ * Contents of this struct are overwritten by the fallbackDetector.
*/
static ADGameDescription s_fallbackDesc = {
"",
@@ -133,6 +133,8 @@ static ADGameDescription s_fallbackDesc = {
Common::GUIO_NONE
};
+static char s_fallbackGameIdBuf[256];
+
static const ADParams detectionParams = {
// Pointer to ADGameDescription or its superset structure
@@ -314,9 +316,12 @@ const ADGameDescription *SciMetaEngine::fallbackDetect(const Common::FSList &fsl
return 0;
}
reg_t game_obj = segMan->lookupScriptExport(0, 0);
- const char *gameId = segMan->getObjectName(game_obj);
- debug(2, "Detected ID: \"%s\" at %04x:%04x", gameId, PRINT_REG(game_obj));
- s_fallbackDesc.gameid = convertSierraGameId(gameId, &s_fallbackDesc.flags, resMan);
+ const char *sierraGameId = segMan->getObjectName(game_obj);
+ debug(2, "Detected ID: \"%s\" at %04x:%04x", sierraGameId, PRINT_REG(game_obj));
+ Common::String gameId = convertSierraGameId(sierraGameId, &s_fallbackDesc.flags, resMan);
+ strncpy(s_fallbackGameIdBuf, gameId.c_str(), sizeof(s_fallbackGameIdBuf) - 1);
+ s_fallbackGameIdBuf[sizeof(s_fallbackGameIdBuf) - 1] = 0; // Make sure string is NULL terminated
+ s_fallbackDesc.gameid = s_fallbackGameIdBuf;
delete segMan;
// Try to determine the game language
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp
index b48ec13448..f92c67505c 100644
--- a/engines/sci/engine/game.cpp
+++ b/engines/sci/engine/game.cpp
@@ -109,7 +109,7 @@ static const OldNewIdTableEntry s_oldNewTable[] = {
{ "", "", SCI_VERSION_NONE }
};
-const char *convertSierraGameId(const char *gameId, uint32 *gameFlags, ResourceManager *resMan) {
+Common::String convertSierraGameId(const char *gameId, uint32 *gameFlags, ResourceManager *resMan) {
// Convert the id to lower case, so that we match all upper/lower case variants.
Common::String sierraId = gameId;
sierraId.toLowercase();
@@ -174,8 +174,7 @@ const char *convertSierraGameId(const char *gameId, uint32 *gameFlags, ResourceM
return "qfg3";
}
- // FIXME: Evil use of strdup here (we are leaking that memory, too)
- return strdup(sierraId.c_str());
+ return sierraId;
}
#ifdef USE_OLD_MUSIC_FUNCTIONS
diff --git a/engines/sci/engine/vm.h b/engines/sci/engine/vm.h
index da17119507..bc99f529aa 100644
--- a/engines/sci/engine/vm.h
+++ b/engines/sci/engine/vm.h
@@ -432,7 +432,7 @@ void script_uninstantiate(SegManager *segMan, int script_nr);
* @param[in] gameFlags The game's flags, which are adjusted accordingly for demos
* @return The equivalent ScummVM game id
*/
-const char *convertSierraGameId(const char *gameId, uint32 *gameFlags, ResourceManager *resMan);
+Common::String convertSierraGameId(const char *gameId, uint32 *gameFlags, ResourceManager *resMan);
/**
* Initializes an SCI game