From 38bf9be94871906a01c84dcc304756b6e8ec26c6 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 27 May 2021 20:11:59 +0200 Subject: [PATCH] Fix some more memory leaks. --- src/zip.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/zip.cpp b/src/zip.cpp index 121b824..f2e458f 100644 --- a/src/zip.cpp +++ b/src/zip.cpp @@ -46,6 +46,7 @@ std::vector list(const fs::path &filepath) toc.emplace_back(archive_entry_pathname_utf8(entry)); archive_read_data_skip(zipfile); } + close_file(zipfile, filepath); return toc; @@ -69,12 +70,15 @@ std::string read_file(const fs::path &filepath, std::string_view entry_path) if (result_length != length) { + close_file(zipfile, filepath); + throw exception{ format(translate("Could not read {0:s} in {1:s}.").str(), entry_path, filepath.string())}; } close_file(zipfile, filepath); + return filecontents; } archive_read_data_skip(zipfile); @@ -95,6 +99,8 @@ struct archive *open_file(const fs::path &filepath) auto result{archive_read_open_filename(zipfile, filepath.c_str(), 10240)}; if (result != ARCHIVE_OK) { + close_file(zipfile, filepath); + throw exception{format(translate("Could not open {0:s}.").str(), filepath.string())}; }