[Scummvm-cvs-logs] SF.net SVN: scummvm:[48237] scummvm/branches/branch-1-1-0/engines/saga
h00ligan at users.sourceforge.net
h00ligan at users.sourceforge.net
Thu Mar 11 21:33:27 CET 2010
Revision: 48237
http://scummvm.svn.sourceforge.net/scummvm/?rev=48237&view=rev
Author: h00ligan
Date: 2010-03-11 20:33:27 +0000 (Thu, 11 Mar 2010)
Log Message:
-----------
backport bug#2963556 SAGA: Memory leaks
Modified Paths:
--------------
scummvm/branches/branch-1-1-0/engines/saga/isomap.cpp
scummvm/branches/branch-1-1-0/engines/saga/isomap.h
scummvm/branches/branch-1-1-0/engines/saga/saveload.cpp
scummvm/branches/branch-1-1-0/engines/saga/script.h
Modified: scummvm/branches/branch-1-1-0/engines/saga/isomap.cpp
===================================================================
--- scummvm/branches/branch-1-1-0/engines/saga/isomap.cpp 2010-03-11 19:47:59 UTC (rev 48236)
+++ scummvm/branches/branch-1-1-0/engines/saga/isomap.cpp 2010-03-11 20:33:27 UTC (rev 48237)
@@ -87,13 +87,8 @@
IsoMap::IsoMap(SagaEngine *vm) : _vm(vm) {
_tileData = NULL;
- _tilesCount = 0;
- _tilePlatformList = NULL;
- _tilePlatformsCount = 0;
- _metaTileList = NULL;
- _metaTilesCount = 0;
- _multiTable = NULL;
- _multiCount = 0;
+ _tileDataLength = 0;
+
_multiTableData = NULL;
_multiDataCount = 0;
_viewScroll.x = (128 - 8) * 16;
@@ -105,28 +100,23 @@
void IsoMap::loadImages(const byte *resourcePointer, size_t resourceLength) {
IsoTileData *tileData;
uint16 i;
+ size_t offsetDiff;
if (resourceLength == 0) {
error("IsoMap::loadImages wrong resourceLength");
}
- _tileData = (byte*)malloc(resourceLength);
- _tileDataLength = resourceLength;
- memcpy(_tileData, resourcePointer, resourceLength);
- MemoryReadStreamEndian readS(_tileData, _tileDataLength, _vm->isBigEndian());
+ MemoryReadStreamEndian readS(resourcePointer, resourceLength, _vm->isBigEndian());
readS.readUint16(); // skip
- _tilesCount = readS.readUint16();
- _tilesCount = _tilesCount / SAGA_ISOTILEDATA_LEN;
+ i = readS.readUint16();
+ i = i / SAGA_ISOTILEDATA_LEN;
+ _tilesTable.resize(i);
readS.seek(0);
- _tilesTable = (IsoTileData *)malloc(_tilesCount * sizeof(*_tilesTable));
- if (_tilesTable == NULL) {
- memoryError("IsoMap::loadImages");
- }
- for (i = 0; i < _tilesCount; i++) {
+ for (i = 0; i < _tilesTable.size(); i++) {
tileData = &_tilesTable[i];
tileData->height = readS.readByte();
tileData->attributes = readS.readSByte();
@@ -136,6 +126,15 @@
readS.readByte(); //skip
}
+ offsetDiff = readS.pos();
+
+ _tileDataLength = resourceLength - offsetDiff;
+ _tileData = (byte*)malloc(_tileDataLength);
+ memcpy(_tileData, resourcePointer + offsetDiff, _tileDataLength);
+
+ for (i = 0; i < _tilesTable.size(); i++) {
+ _tilesTable[i].offset -= offsetDiff;
+ }
}
void IsoMap::loadPlatforms(const byte * resourcePointer, size_t resourceLength) {
@@ -148,13 +147,10 @@
MemoryReadStreamEndian readS(resourcePointer, resourceLength, _vm->isBigEndian());
- _tilePlatformsCount = resourceLength / SAGA_TILEPLATFORMDATA_LEN;
- _tilePlatformList = (TilePlatformData *)malloc(_tilePlatformsCount * sizeof(*_tilePlatformList));
- if (_tilePlatformList == NULL) {
- memoryError("IsoMap::loadPlatforms");
- }
+ i = resourceLength / SAGA_TILEPLATFORMDATA_LEN;
+ _tilePlatformList.resize(i);
- for (i = 0; i < _tilePlatformsCount; i++) {
+ for (i = 0; i < _tilePlatformList.size(); i++) {
tilePlatformData = &_tilePlatformList[i];
tilePlatformData->metaTile = readS.readSint16();
tilePlatformData->height = readS.readSint16();
@@ -198,14 +194,10 @@
}
MemoryReadStreamEndian readS(resourcePointer, resourceLength, _vm->isBigEndian());
- _metaTilesCount = resourceLength / SAGA_METATILEDATA_LEN;
+ i = resourceLength / SAGA_METATILEDATA_LEN;
+ _metaTileList.resize(i);
- _metaTileList = (MetaTileData *)malloc(_metaTilesCount * sizeof(*_metaTileList));
- if (_metaTileList == NULL) {
- memoryError("IsoMap::loadMetaTiles");
- }
-
- for (i = 0; i < _metaTilesCount; i++) {
+ for (i = 0; i < _metaTileList.size(); i++) {
metaTileData = &_metaTileList[i];
metaTileData->highestPlatform = readS.readUint16();
metaTileData->highestPixel = readS.readUint16();
@@ -225,13 +217,10 @@
}
MemoryReadStreamEndian readS(resourcePointer, resourceLength, _vm->isBigEndian());
- _multiCount = readS.readUint16();
- _multiTable = (MultiTileEntryData *)malloc(_multiCount * sizeof(*_multiTable));
- if (_multiTable == NULL) {
- memoryError("IsoMap::loadMulti");
- }
+ i = readS.readUint16();
+ _multiTable.resize(i);
- for (i = 0; i < _multiCount; i++) {
+ for (i = 0; i < _multiTable.size(); i++) {
multiTileEntryData = &_multiTable[i];
readS.readUint32();//skip
multiTileEntryData->offset = readS.readSint16();
@@ -247,7 +236,7 @@
offsetDiff = (readS.pos() - 2);
- for (i = 0; i < _multiCount; i++) {
+ for (i = 0; i < _multiTable.size(); i++) {
_multiTable[i].offset -= offsetDiff;
}
@@ -260,18 +249,14 @@
}
void IsoMap::freeMem() {
+ _tilesTable.clear();
+ _tilePlatformList.clear();
+ _metaTileList.clear();
+ _multiTable.clear();
+
free(_tileData);
_tileData = NULL;
- _tilesCount = 0;
- free(_tilePlatformList);
- _tilePlatformList = NULL;
- _tilePlatformsCount = 0;
- free(_metaTileList);
- _metaTileList = NULL;
- _metaTilesCount = 0;
- free(_multiTable);
- _multiTable = NULL;
- _multiCount = 0;
+
free(_multiTableData);
_multiTableData = NULL;
_multiDataCount = 0;
@@ -350,7 +335,7 @@
mv = absV - rv;
tileIndex = 0;
- for (i = 0; i < _multiCount; i++) {
+ for (i = 0; i < _multiTable.size(); i++) {
multiTileEntryData = &_multiTable[i];
if ((multiTileEntryData->u == mu) &&
@@ -540,7 +525,7 @@
Point platformPoint;
platformPoint = point;
- if (_metaTilesCount <= metaTileIndex) {
+ if (_metaTileList.size() <= metaTileIndex) {
error("IsoMap::drawMetaTile wrong metaTileIndex");
}
@@ -567,7 +552,7 @@
Point platformPoint;
platformPoint = point;
- if (_metaTilesCount <= metaTileIndex) {
+ if (_metaTileList.size() <= metaTileIndex) {
error("IsoMap::drawMetaTile wrong metaTileIndex");
}
@@ -595,7 +580,7 @@
uint16 tileIndex;
Location copyLocation(location);
- if (_tilePlatformsCount <= platformIndex) {
+ if (_tilePlatformList.size() <= platformIndex) {
error("IsoMap::drawPlatform wrong platformIndex");
}
@@ -649,7 +634,7 @@
Point s0;
uint16 tileIndex;
- if (_tilePlatformsCount <= platformIndex) {
+ if (_tilePlatformList.size() <= platformIndex) {
error("IsoMap::drawPlatform wrong platformIndex");
}
@@ -709,7 +694,7 @@
int bgRunCount;
int fgRunCount;
- if (tileIndex >= _tilesCount) {
+ if (tileIndex >= _tilesTable.size()) {
error("IsoMap::drawTile wrong tileIndex");
}
@@ -1025,7 +1010,7 @@
metaTileIndex = _tileMap.tilePlatforms[uc][vc];
}
- if (_metaTilesCount <= metaTileIndex) {
+ if (_metaTileList.size() <= (uint)metaTileIndex) {
error("IsoMap::getTile wrong metaTileIndex");
}
@@ -1034,7 +1019,7 @@
return 0;
}
- if (_tilePlatformsCount <= platformIndex) {
+ if (_tilePlatformList.size() <= (uint)platformIndex) {
error("IsoMap::getTile wrong platformIndex");
}
@@ -1608,8 +1593,8 @@
void IsoMap::setTileDoorState(int doorNumber, int doorState) {
MultiTileEntryData *multiTileEntryData;
- if ((doorNumber < 0) || (doorNumber >= _multiCount)) {
- error("setTileDoorState: doorNumber >= _multiCount");
+ if ((doorNumber < 0) || ((uint)doorNumber >= _multiTable.size())) {
+ error("setTileDoorState: doorNumber >= _multiTable.size()");
}
multiTileEntryData = &_multiTable[doorNumber];
Modified: scummvm/branches/branch-1-1-0/engines/saga/isomap.h
===================================================================
--- scummvm/branches/branch-1-1-0/engines/saga/isomap.h 2010-03-11 19:47:59 UTC (rev 48236)
+++ scummvm/branches/branch-1-1-0/engines/saga/isomap.h 2010-03-11 20:33:27 UTC (rev 48237)
@@ -215,16 +215,12 @@
byte *_tileData;
size_t _tileDataLength;
- uint16 _tilesCount;
- IsoTileData *_tilesTable;
+ Common::Array<IsoTileData> _tilesTable;
- uint16 _tilePlatformsCount;
- TilePlatformData *_tilePlatformList;
- uint16 _metaTilesCount;
- MetaTileData *_metaTileList;
+ Common::Array<TilePlatformData> _tilePlatformList;
+ Common::Array<MetaTileData> _metaTileList;
- uint16 _multiCount;
- MultiTileEntryData *_multiTable;
+ Common::Array<MultiTileEntryData> _multiTable;
uint16 _multiDataCount;
int16 *_multiTableData;
Modified: scummvm/branches/branch-1-1-0/engines/saga/saveload.cpp
===================================================================
--- scummvm/branches/branch-1-1-0/engines/saga/saveload.cpp 2010-03-11 19:47:59 UTC (rev 48236)
+++ scummvm/branches/branch-1-1-0/engines/saga/saveload.cpp 2010-03-11 20:33:27 UTC (rev 48237)
@@ -301,6 +301,7 @@
Graphics::Surface *thumbnail = new Graphics::Surface();
assert(thumbnail);
Graphics::loadThumbnail(*in, *thumbnail);
+ thumbnail->free();
delete thumbnail;
thumbnail = 0;
Modified: scummvm/branches/branch-1-1-0/engines/saga/script.h
===================================================================
--- scummvm/branches/branch-1-1-0/engines/saga/script.h 2010-03-11 19:47:59 UTC (rev 48236)
+++ scummvm/branches/branch-1-1-0/engines/saga/script.h 2010-03-11 20:33:27 UTC (rev 48237)
@@ -308,7 +308,7 @@
StringsTable _mainStrings;
Script(SagaEngine *vm);
- ~Script();
+ virtual ~Script();
void loadModule(int scriptModuleNumber);
void freeModules();
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