[Scummvm-git-logs] scummvm branch-3-0 -> 2b96382a2843289ec728fa66daf3e5a8f3663945

AndywinXp noreply at scummvm.org
Fri Jan 9 19:13:03 UTC 2026


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:
2b96382a28 SWORD1: Fix leaks, use after delete and non-closed files


Commit: 2b96382a2843289ec728fa66daf3e5a8f3663945
    https://github.com/scummvm/scummvm/commit/2b96382a2843289ec728fa66daf3e5a8f3663945
Author: AndywinXp (andywinxp at gmail.com)
Date: 2026-01-09T20:12:55+01:00

Commit Message:
SWORD1: Fix leaks, use after delete and non-closed files

This should fix #16443 for good.

"SWORD1: File::open() assertion in prepareMusicStreaming() (PSX demo)"

Thanks to dwatteau and lephilousophe for uncovering yet another
instance of me forgetting to close files on early returns :P

Changed paths:
    engines/sword1/sound.cpp


diff --git a/engines/sword1/sound.cpp b/engines/sword1/sound.cpp
index fae66a8da88..452155e92a2 100644
--- a/engines/sword1/sound.cpp
+++ b/engines/sword1/sound.cpp
@@ -516,13 +516,13 @@ void Sound::startSpeech(uint16 roomNo, uint16 localNo) {
 				break;
 			}
 
+		file.close();
+
 		if (locIndex == 0xFFFFFFFF) {
 			warning("Could not find local number %d in room %d in speech.inf", roomNo, localNo);
 			return;
 		}
 
-		file.close();
-
 		index = _cowHeader[(roomOffset + locIndex) * 2];
 		sampleFileSize = _cowHeader[(roomOffset + locIndex) * 2 + 1];
 	} else {
@@ -560,8 +560,9 @@ void Sound::startSpeech(uint16 roomNo, uint16 localNo) {
 				memset(_speechSample, 0, _speechSize);
 
 				SwordEngine::_systemVars.speechRunning = expandSpeech(compSample, _speechSample, sampleFileSize);
-				free(compSample);
 			}
+
+			free(compSample);
 		}
 	}
 }
@@ -998,6 +999,7 @@ bool Sound::prepareMusicStreaming(const Common::Path &filename, int newHandleId,
 	}
 
 	delete _compressedMusicStream[newHandleId];
+	_compressedMusicStream[newHandleId] = nullptr;
 
 	if (assignedMode == MusWav) {
 		if (_musicFile[newHandleId].read(&wavHead, sizeof(WaveHeader)) != sizeof(WaveHeader)) {
@@ -1033,14 +1035,19 @@ bool Sound::prepareMusicStreaming(const Common::Path &filename, int newHandleId,
 		Common::File tableFile;
 		if (!tableFile.open("tunes.tab")) {
 			debug(5, "Sound::streamMusicFile(): couldn't open the tunes.tab file, bailing out...");
+			_musicFile[newHandleId].close();
 			return false;
 		}
 
 		// The PSX demo has a broken/truncated tunes.tab. So we check here
 		// that the offset is not beyond the end of the file.
 		int32 tableOffset = (tuneId - 1) * 8;
-		if (tableOffset >= tableFile.size())
+		if (tableOffset >= tableFile.size()) {
+			tableFile.close();
+			_musicFile[newHandleId].close();
 			return false;
+		}
+
 		tableFile.seek(tableOffset, SEEK_SET);
 		uint32 offset = tableFile.readUint32LE() * 0x800;
 		uint32 size = tableFile.readUint32LE();




More information about the Scummvm-git-logs mailing list