aboutsummaryrefslogtreecommitdiff
path: root/engines/lastexpress
diff options
context:
space:
mode:
authorJulien Templier2010-10-24 22:15:36 +0000
committerJulien Templier2010-10-24 22:15:36 +0000
commit859c1c2c08c39262de6b6ba6e1169bb03d14353a (patch)
tree04dadb9930a36cbaac28284bcff57260059a6a92 /engines/lastexpress
parente4dc5336db4f2e864aa5b7d1496c00169ef69b50 (diff)
downloadscummvm-rg350-859c1c2c08c39262de6b6ba6e1169bb03d14353a.tar.gz
scummvm-rg350-859c1c2c08c39262de6b6ba6e1169bb03d14353a.tar.bz2
scummvm-rg350-859c1c2c08c39262de6b6ba6e1169bb03d14353a.zip
LASTEXPRESS: Fix issues when copying debugger commands
- Properly free allocated memory in resetCommand() - Make sure _commandParams strings are null-terminated svn-id: r53778
Diffstat (limited to 'engines/lastexpress')
-rw-r--r--engines/lastexpress/debug.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/engines/lastexpress/debug.cpp b/engines/lastexpress/debug.cpp
index 62496c9111..b32c49dc33 100644
--- a/engines/lastexpress/debug.cpp
+++ b/engines/lastexpress/debug.cpp
@@ -101,11 +101,10 @@ Debugger::~Debugger() {
DebugMan.clearAllDebugChannels();
delete _soundStream;
+ resetCommand();
// Zero passed pointers
_engine = NULL;
- _command = NULL;
- _commandParams = NULL;
}
//////////////////////////////////////////////////////////////////////////
@@ -116,7 +115,11 @@ bool Debugger::hasCommand() const {
}
void Debugger::resetCommand() {
- _command = NULL;
+ SAFE_DELETE(_command);
+ for (int i = 0; i < _numParams; i++)
+ free(_commandParams[i]);
+
+ free(_commandParams);
_commandParams = NULL;
_numParams = 0;
}
@@ -126,15 +129,15 @@ int Debugger::getNumber(const char *arg) const {
}
void Debugger::copyCommand(int argc, const char **argv) {
- _commandParams = (char **)malloc((uint)argc);
+ _commandParams = (char **)malloc(sizeof(char *) * argc);
if (!_commandParams)
return;
_numParams = argc;
for (int i = 0; i < _numParams; i++) {
- _commandParams[i] = (char *)malloc(strlen(argv[i]));
- strcpy(_commandParams[i], "");
+ _commandParams[i] = (char *)malloc(strlen(argv[i]) + 1);
+ memset(_commandParams[i], NULL, strlen(argv[i]) + 1);
strcpy(_commandParams[i], argv[i]);
}