From 5140438d6073010b9c79793c5cfd43c56769e474 Mon Sep 17 00:00:00 2001 From: sluicebox <22204938+sluicebox@users.noreply.github.com> Date: Mon, 30 Oct 2023 11:22:12 -0700 Subject: [PATCH] TRECISION: Fix memory leaks. PVS-Studio V773 --- engines/trecision/console.cpp | 20 ++++++++++---------- engines/trecision/video.cpp | 4 +++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/engines/trecision/console.cpp b/engines/trecision/console.cpp index f7729af3b87..5c4a495db16 100644 --- a/engines/trecision/console.cpp +++ b/engines/trecision/console.cpp @@ -87,12 +87,12 @@ bool Console::Cmd_DumpAnim(int argc, const char **argv) { Common::SeekableReadStream *dataFile = animFile.createReadStreamForMember(fileName); - Common::DumpFile *outFile = new Common::DumpFile(); + Common::DumpFile outFile; Common::String outName = fileName + ".dump"; - outFile->open(outName); - outFile->writeStream(dataFile, dataFile->size()); - outFile->finalize(); - outFile->close(); + outFile.open(outName); + outFile.writeStream(dataFile, dataFile->size()); + outFile.finalize(); + outFile.close(); animFile.close(); @@ -114,12 +114,12 @@ bool Console::Cmd_DumpFile(int argc, const char **argv) { Common::SeekableReadStream *dataFile = fileName.hasSuffix(".cr") ? _vm->_dataFile.createReadStreamForCompressedMember(fileName) : _vm->_dataFile.createReadStreamForMember(fileName); - Common::DumpFile *outFile = new Common::DumpFile(); + Common::DumpFile outFile; Common::String outName = fileName + ".dump"; - outFile->open(outName); - outFile->writeStream(dataFile, dataFile->size()); - outFile->finalize(); - outFile->close(); + outFile.open(outName); + outFile.writeStream(dataFile, dataFile->size()); + outFile.finalize(); + outFile.close(); return true; } diff --git a/engines/trecision/video.cpp b/engines/trecision/video.cpp index 4951dbf16fb..2e3b74c4855 100644 --- a/engines/trecision/video.cpp +++ b/engines/trecision/video.cpp @@ -129,8 +129,10 @@ NightlongAmigaDecoder::AmigaVideoTrack::AmigaVideoTrack(const Common::String &fi Common::File *stream = new Common::File(); stream->open(fileName); - if (!stream->isOpen()) + if (!stream->isOpen()) { + delete stream; return; + } _curFrame = 0; _frameCount = 10; // TODO: Anything > 1 to keep playing till the audio is done