Skip to content

Commit

Permalink
WAGE: Fix numerpous memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Jan 6, 2016
1 parent 28a02b8 commit 6b428f2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
16 changes: 14 additions & 2 deletions engines/wage/script.cpp
Expand Up @@ -119,6 +119,7 @@ bool Script::execute(World *world, int loopCount, String *inputText, Designed *i
Operand *op = readOperand();
// TODO check op type is string or number, or something good...
appendText(op->toString());
delete op;
byte d = _data->readByte();
if (d != 0xFD)
warning("Operand 0x8B (PRINT) End Byte != 0xFD");
Expand All @@ -130,6 +131,7 @@ bool Script::execute(World *world, int loopCount, String *inputText, Designed *i
// TODO check op type is string.
_handled = true;
callbacks->playSound(op->toString());
delete op;
byte d = _data->readByte();
if (d != 0xFD)
warning("Operand 0x8B (PRINT) End Byte != 0xFD");
Expand Down Expand Up @@ -449,6 +451,9 @@ void Script::processIf() {

bool condResult = eval(lhs, op, rhs);

delete lhs;
delete rhs;

if (logicalOp == 1) {
result = (result && condResult);
} else if (logicalOp == 2) {
Expand All @@ -475,9 +480,12 @@ void Script::processIf() {

void Script::skipIf() {
do {
readOperand();
Operand *lhs = readOperand();
readOperator();
readOperand();
Operand *rhs = readOperand();

delete lhs;
delete rhs;
} while (_data->readByte() != 0xFE);
}

Expand Down Expand Up @@ -884,6 +892,9 @@ void Script::processMove() {
error("No end for MOVE: %02x", skip);

evaluatePair(what, "M", to);

delete what;
delete to;
}

void Script::processLet() {
Expand All @@ -904,6 +915,7 @@ void Script::processLet() {
Operand *operand = readOperand();
// TODO assert that value is NUMBER
int16 value = operand->_value.number;
delete operand;
if (lastOp != NULL) {
if (lastOp[0] == '+')
result += value;
Expand Down
5 changes: 5 additions & 0 deletions engines/wage/script.h
Expand Up @@ -109,6 +109,11 @@ class Script {
_type = type;
}

~Operand() {
if (_type == STRING)
delete _value.string;
}

Common::String toString() {
char buf[128];

Expand Down

0 comments on commit 6b428f2

Please sign in to comment.