From 77779562126d8f2f8595f9ae85ad17cdc948d941 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 13 Feb 2022 13:20:58 +0000 Subject: [PATCH] zip file stream memory leak fix proposa,=l, switching to smart pointer. --- Sources/Core/ZipFileSystem.cpp | 8 +++----- Sources/Core/ZipFileSystem.h | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/Sources/Core/ZipFileSystem.cpp b/Sources/Core/ZipFileSystem.cpp index b144e9e9e..9a1cabfd2 100644 --- a/Sources/Core/ZipFileSystem.cpp +++ b/Sources/Core/ZipFileSystem.cpp @@ -58,7 +58,7 @@ namespace spades { SPADES_MARK_FUNCTION(); if (streaming) { unzCloseCurrentFile(zip); - SPAssert(this == fs->currentStream); + SPAssert(this == fs->currentStream.get()); fs->currentStream = NULL; } } @@ -79,7 +79,7 @@ namespace spades { SPRaise("Zip file close error: 0x%08x", ret); } - SPAssert(this == fs->currentStream); + SPAssert(this == fs->currentStream.get()); fs->currentStream = NULL; } } @@ -343,7 +343,7 @@ namespace spades { unzOpenCurrentFile(zip); try { - currentStream = new ZipFileInputStream(this, zip); + currentStream.reset(new ZipFileInputStream(this, zip)); // load all data to allow seeking auto stream = stmp::make_unique(); try { @@ -354,10 +354,8 @@ namespace spades { } currentStream->ForceCloseUnzipFile(); stream->SetPosition(0); - delete currentStream; return stream; } catch (...) { - delete currentStream; throw; } } catch (...) { diff --git a/Sources/Core/ZipFileSystem.h b/Sources/Core/ZipFileSystem.h index d29c1a943..d07cb9aa3 100644 --- a/Sources/Core/ZipFileSystem.h +++ b/Sources/Core/ZipFileSystem.h @@ -44,7 +44,7 @@ namespace spades { std::map files; - ZipFileInputStream *currentStream; + std::unique_ptr currentStream; uint64_t cursorPos;