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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Thu Feb 18 00:36:50 CET 2010


Revision: 48083
          http://scummvm.svn.sourceforge.net/scummvm/?rev=48083&view=rev
Author:   fingolfin
Date:     2010-02-17 23:36:50 +0000 (Wed, 17 Feb 2010)

Log Message:
-----------
SCI: Remove hack in convertSierraGameId which caused a memory leak

Modified Paths:
--------------
    scummvm/trunk/engines/sci/detection.cpp
    scummvm/trunk/engines/sci/engine/game.cpp
    scummvm/trunk/engines/sci/engine/vm.h

Modified: scummvm/trunk/engines/sci/detection.cpp
===================================================================
--- scummvm/trunk/engines/sci/detection.cpp	2010-02-17 23:05:51 UTC (rev 48082)
+++ scummvm/trunk/engines/sci/detection.cpp	2010-02-17 23:36:50 UTC (rev 48083)
@@ -121,7 +121,7 @@
 
 /**
  * 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,7 +133,9 @@
 	Common::GUIO_NONE
 };
 
+static char s_fallbackGameIdBuf[256];
 
+
 static const ADParams detectionParams = {
 	// Pointer to ADGameDescription or its superset structure
 	(const byte *)Sci::SciGameDescriptions,
@@ -314,9 +316,12 @@
 		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

Modified: scummvm/trunk/engines/sci/engine/game.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/game.cpp	2010-02-17 23:05:51 UTC (rev 48082)
+++ scummvm/trunk/engines/sci/engine/game.cpp	2010-02-17 23:36:50 UTC (rev 48083)
@@ -109,7 +109,7 @@
 	{ "", "", 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 @@
 		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

Modified: scummvm/trunk/engines/sci/engine/vm.h
===================================================================
--- scummvm/trunk/engines/sci/engine/vm.h	2010-02-17 23:05:51 UTC (rev 48082)
+++ scummvm/trunk/engines/sci/engine/vm.h	2010-02-17 23:36:50 UTC (rev 48083)
@@ -432,7 +432,7 @@
  * @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


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