From 0955d208a2ae62fb676567f46eb0d7f238b2573a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Kongstad?= Date: Thu, 26 Sep 2019 15:03:50 +0200 Subject: [PATCH] idmap2: ZipFile::Open: fix potential memory leak Even if OpenArchive in libziparchive returns a non-zero value (indicating failure), it will have allocated memory that needs to be freed via CloseArchive. Add the missing call. Test: valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 $ANDROID_HOST_OUT/nativetest64/idmap2_tests/idmap2_tests Change-Id: I92d47459c27e62ba4544327d7b7f3c4106e6ad34 --- cmds/idmap2/libidmap2/ZipFile.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/cmds/idmap2/libidmap2/ZipFile.cpp b/cmds/idmap2/libidmap2/ZipFile.cpp index 4f5e3a45f1831..1e1a218163f04 100644 --- a/cmds/idmap2/libidmap2/ZipFile.cpp +++ b/cmds/idmap2/libidmap2/ZipFile.cpp @@ -34,6 +34,7 @@ std::unique_ptr ZipFile::Open(const std::string& path) { ::ZipArchiveHandle handle; int32_t status = ::OpenArchive(path.c_str(), &handle); if (status != 0) { + ::CloseArchive(handle); return nullptr; } return std::unique_ptr(new ZipFile(handle));