From 063bc245642b52e1064d29f233f46ad8db0a9a17 Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Wed, 25 May 2022 14:04:45 -0700 Subject: [PATCH] Fix memory leak in OTA verifier code StartIteration() allocates some memory, which are release in EndIteration(). Since we never called EndIteration(), these memories are leaked. Test: th Bug: 233209345 Change-Id: I71c1d6eec16b8ac20c35e180f34fec50d0baec1a --- otautil/verifier.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/otautil/verifier.cpp b/otautil/verifier.cpp index 8a65566e..83ad7082 100644 --- a/otautil/verifier.cpp +++ b/otautil/verifier.cpp @@ -309,13 +309,15 @@ int verify_file(VerifierInterface* package, const std::vector& keys } static std::vector IterateZipEntriesAndSearchForKeys(const ZipArchiveHandle& handle) { - void* cookie; + void* cookie{}; + int32_t iter_status = StartIteration(handle, &cookie, "", "x509.pem"); if (iter_status != 0) { LOG(ERROR) << "Failed to iterate over entries in the certificate zipfile: " << ErrorCodeString(iter_status); return {}; } + std::unique_ptr cookie_guard(cookie, &EndIteration); std::vector result;