Skip to content

Commit

Permalink
TSAGE: Allocate resource decoding buffer on the heap
Browse files Browse the repository at this point in the history
  • Loading branch information
Templier committed Jun 23, 2011
1 parent 5aa1877 commit 367605d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
24 changes: 21 additions & 3 deletions engines/toon/path.cpp
Expand Up @@ -342,8 +342,15 @@ int32 PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
curX = destx;
curY = desty;

int32 retPathX[4096];
int32 retPathY[4096];
int32 *retPathX = (int32 *)malloc(4096 * sizeof(int32));
int32 *retPathY = (int32 *)malloc(4096 * sizeof(int32));
if (!retPathX || !retPathY) {
free(retPathX);
free(retPathY);

error("[PathFinding::findPath] Cannot allocate pathfinding buffers");
}

int32 numpath = 0;

retPathX[numpath] = curX;
Expand Down Expand Up @@ -377,8 +384,12 @@ int32 PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {
}
}

if (bestX < 0 || bestY < 0)
if (bestX < 0 || bestY < 0) {
free(retPathX);
free(retPathY);

return 0;
}

retPathX[numpath] = bestX;
retPathY[numpath] = bestY;
Expand All @@ -389,13 +400,20 @@ int32 PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) {

memcpy(_tempPathX, retPathX, sizeof(int32) * numpath);
memcpy(_tempPathY, retPathY, sizeof(int32) * numpath);

free(retPathX);
free(retPathY);

return true;
}

curX = bestX;
curY = bestY;
}

free(retPathX);
free(retPathY);

return false;
}

Expand Down
11 changes: 9 additions & 2 deletions engines/tsage/resources.cpp
Expand Up @@ -237,8 +237,13 @@ byte *TLib::getResource(uint16 id, bool suppressErrors) {
uint16 ctrCurrent = 0x102, ctrMax = 0x200;
uint16 word_48050 = 0, currentToken = 0, word_48054 =0;
byte byte_49068 = 0, byte_49069 = 0;
DecodeReference table[0x1000];
for (int i = 0; i < 0x1000; ++i) {

const uint tableSize = 0x1000;
DecodeReference *table = (DecodeReference *)malloc(tableSize * sizeof(DecodeReference));
if (!table)
error("[TLib::getResource] Cannot allocate table buffer");

for (int i = 0; i < tableSize; ++i) {
table[i].vByte = table[i].vWord = 0;
}
Common::Stack<uint16> tokenList;
Expand Down Expand Up @@ -302,6 +307,8 @@ byte *TLib::getResource(uint16 id, bool suppressErrors) {
}
}

free(table);

assert(bytesWritten == re->uncompressedSize);
delete compStream;
return dataOut;
Expand Down

0 comments on commit 367605d

Please sign in to comment.