From 859c1c2c08c39262de6b6ba6e1169bb03d14353a Mon Sep 17 00:00:00 2001 From: Julien Templier Date: Sun, 24 Oct 2010 22:15:36 +0000 Subject: LASTEXPRESS: Fix issues when copying debugger commands - Properly free allocated memory in resetCommand() - Make sure _commandParams strings are null-terminated svn-id: r53778 --- engines/lastexpress/debug.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'engines/lastexpress') 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]); } -- cgit v1.2.3