File 19283.patch of Package openrct2
From e3447c363b91b49dc5b0b673a2e2e36ac78266e0 Mon Sep 17 00:00:00 2001
From: icy17 <1061499390@qq.com>
Date: Fri, 27 Jan 2023 11:59:09 +0800
Subject: [PATCH 1/2] fix memleak
---
src/openrct2/core/Zip.cpp | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/openrct2/core/Zip.cpp b/src/openrct2/core/Zip.cpp
index 04d8a7410656..510e9e4ffd89 100644
--- a/src/openrct2/core/Zip.cpp
+++ b/src/openrct2/core/Zip.cpp
@@ -169,13 +169,18 @@ class ZipArchive final : public IZipArchive
auto source = zip_source_buffer(_zip, writeBuffer.data(), writeBuffer.size(), 0);
auto index = GetIndexFromPath(path);
+ zip_int64_t res = 0;
if (index.has_value())
{
- zip_replace(_zip, index.value(), source);
+ res = zip_replace(_zip, index.value(), source);
}
else
{
- zip_add(_zip, path.data(), source);
+ res = zip_add(_zip, path.data(), source);
+ }
+ if (res == -1)
+ {
+ zip_source_free(source);
}
}
From 636b5e55a23711b0a5772823921aa303b5cf07f8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com>
Date: Thu, 9 Mar 2023 02:31:28 +0200
Subject: [PATCH 2/2] Replace deprecated functions and throw on error
---
src/openrct2/core/Zip.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/openrct2/core/Zip.cpp b/src/openrct2/core/Zip.cpp
index 510e9e4ffd89..9ecae3aa20d8 100644
--- a/src/openrct2/core/Zip.cpp
+++ b/src/openrct2/core/Zip.cpp
@@ -172,15 +172,16 @@ class ZipArchive final : public IZipArchive
zip_int64_t res = 0;
if (index.has_value())
{
- res = zip_replace(_zip, index.value(), source);
+ res = zip_file_replace(_zip, index.value(), source, 0);
}
else
{
- res = zip_add(_zip, path.data(), source);
+ res = zip_file_add(_zip, path.data(), source, 0);
}
if (res == -1)
{
zip_source_free(source);
+ throw std::runtime_error("Unable to set file contents.");
}
}