[Scummvm-git-logs] scummvm master -> e5239be9255a731750bdcd979546be5eb516d738

kelmer44 noreply at scummvm.org
Tue Sep 16 19:57:22 UTC 2025


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .

Summary:
e5239be925 TOT: Fixes a number of memory leaks


Commit: e5239be9255a731750bdcd979546be5eb516d738
    https://github.com/scummvm/scummvm/commit/e5239be9255a731750bdcd979546be5eb516d738
Author: kelmer (kelmer at gmail.com)
Date: 2025-09-16T21:57:07+02:00

Commit Message:
TOT: Fixes a number of memory leaks

Changed paths:
    engines/tot/anims.cpp
    engines/tot/engine.cpp
    engines/tot/midi.cpp
    engines/tot/sound.cpp
    engines/tot/tot.cpp


diff --git a/engines/tot/anims.cpp b/engines/tot/anims.cpp
index f73f107cc91..397ab205cf9 100644
--- a/engines/tot/anims.cpp
+++ b/engines/tot/anims.cpp
@@ -950,7 +950,9 @@ void drawFlc(
 							palette[1] = 0;
 							palette[2] = 0;
 							if (fullPalette) {
-								g_engine->_graphics->fadePalettes(g_engine->_graphics->getPalette(), palette);
+								byte *gamePalette = g_engine->_graphics->getPalette();
+								g_engine->_graphics->fadePalettes(gamePalette, palette);
+								free(gamePalette);
 								g_engine->_graphics->copyPalette(palette, g_engine->_graphics->_pal);
 							} else if (limitPaletteTo200) {
 								g_engine->_graphics->setPalette(palette, 0, 200);
@@ -967,8 +969,8 @@ void drawFlc(
 								g_engine->_graphics->setPalette(palette);
 								g_engine->_graphics->copyPalette(palette, g_engine->_graphics->_pal);
 							}
+							free(palette);
 						}
-
 						g_engine->_chrono->_gameTick = false;
 					} else {
 						break;
@@ -986,6 +988,7 @@ void drawFlc(
 		}
 	} while (loopNumber <= loop && !g_engine->shouldQuit());
 	flic->stop();
+	delete flic;
 Lexit_proc:
 	animationsFile.close();
 }
diff --git a/engines/tot/engine.cpp b/engines/tot/engine.cpp
index 4f6a9aa4236..1c6d378c6c8 100644
--- a/engines/tot/engine.cpp
+++ b/engines/tot/engine.cpp
@@ -296,7 +296,11 @@ void TotEngine::sprites(bool drawMainCharachter) {
 			if (_isPeterCoughing && !_sound->isVocPlaying()) {
 				_iframe2 = 0;
 			}
-			_curSecondaryAnimationFrame = _secondaryAnimation.bitmap[_secondaryAnimation.dir][_iframe2];
+			if(_curSecondaryAnimationFrame != nullptr) {
+				free(_curSecondaryAnimationFrame);
+			}
+			_curSecondaryAnimationFrame = (byte *)malloc(_secondaryAnimFrameSize);
+			Common::copy(_secondaryAnimation.bitmap[_secondaryAnimation.dir][_iframe2], _secondaryAnimation.bitmap[_secondaryAnimation.dir][_iframe2] + _secondaryAnimFrameSize,  _curSecondaryAnimationFrame);
 		}
 		uint16 curCharFrameW = READ_LE_UINT16(_curCharacterAnimationFrame);
 		uint16 curCharFrameH = READ_LE_UINT16(_curCharacterAnimationFrame + 2);
@@ -350,6 +354,7 @@ void TotEngine::sprites(bool drawMainCharachter) {
 				_curDepth += 1;
 			}
 			_graphics->putImg(_dirtyMainSpriteX, _dirtyMainSpriteY, _characterDirtyRect);
+			free(_characterDirtyRect);
 		} else { // character and animation are in different parts of the screen
 
 			if (drawMainCharachter) {
@@ -383,6 +388,7 @@ void TotEngine::sprites(bool drawMainCharachter) {
 				_curDepth += 1;
 			}
 			_graphics->putImg(_dirtyMainSpriteX, _dirtyMainSpriteY, _characterDirtyRect);
+			free(_characterDirtyRect);
 		}
 	} else if (drawMainCharachter) {
 		drawMainCharacter();
diff --git a/engines/tot/midi.cpp b/engines/tot/midi.cpp
index 775ee531d3f..73621913892 100644
--- a/engines/tot/midi.cpp
+++ b/engines/tot/midi.cpp
@@ -189,6 +189,7 @@ void MidiDriver_AdLib::loadInstrumentBankFromDriver(int32 offset) {
 	uint8 *data = (uint8 *)malloc(128 * (11 + 21));
 	driverFile.read(data, 128 * (11 + 21));
 	loadInstrumentBank(data);
+	free(data);
 	driverFile.close();
 
 	_instrumentBank = _dsfInstrumentBank;
diff --git a/engines/tot/sound.cpp b/engines/tot/sound.cpp
index ced261760dc..d093c5cd920 100644
--- a/engines/tot/sound.cpp
+++ b/engines/tot/sound.cpp
@@ -63,7 +63,10 @@ void SoundManager::init() {
 
 void SoundManager::loadVoc(Common::String vocFile, int32 startPos, int16 size) {
 	Common::File vocResource;
-
+	if(_lastSrcStream) {
+		delete _lastSrcStream;
+		_lastSrcStream = nullptr;
+	}
 	if (size == 0) {
 		if (!vocResource.open(Common::Path(vocFile + ".VOC"))) {
 			showError(266);
diff --git a/engines/tot/tot.cpp b/engines/tot/tot.cpp
index 97dd4c44c69..b370d747ed9 100644
--- a/engines/tot/tot.cpp
+++ b/engines/tot/tot.cpp
@@ -56,6 +56,7 @@ TotEngine::~TotEngine() {
 	delete _graphics;
 	delete _sound;
 	delete _chrono;
+	delete _mouse;
 }
 
 uint32 TotEngine::getFeatures() const {
@@ -1219,6 +1220,9 @@ void TotEngine::initVars() {
 		}
 	}
 
+	_curSecondaryAnimationFrame = nullptr;
+	_characterDirtyRect = nullptr;
+
 	resetGameState();
 	_chrono->_gameTick = false;
 	for (int i = 0; i < kNumScreenOverlays; i++) {
@@ -1284,6 +1288,10 @@ void TotEngine::clearVars() {
 		}
 	}
 
+	if(_curSecondaryAnimationFrame != nullptr) {
+		free(_curSecondaryAnimationFrame);
+	}
+
 	for (int i = 0; i < _secondaryAnimDirCount; i++) {
 		for (int j = 0; j < _secondaryAnimationFrameCount; j++) {
 			if (_secondaryAnimation.bitmap[i][j] != nullptr) {




More information about the Scummvm-git-logs mailing list