From c6d7d6e69b7a435a26209926cb85cbb7fc10f787 Mon Sep 17 00:00:00 2001 From: Robert Shih Date: Wed, 16 Feb 2022 13:35:09 -0800 Subject: [PATCH] wv aidl: fix native handle memory leak [ Merge of go/wvgerrit/145971 ] Bug: 219754570 Test: atest GtsMediaTestCases Change-Id: Id4705d5bc10ba6dfbe878f2d95fdd9ae9d2e9f1d Merged-In: Id4705d5bc10ba6dfbe878f2d95fdd9ae9d2e9f1d --- libwvdrmengine/mediacrypto/aidl_src/WVCryptoPlugin.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libwvdrmengine/mediacrypto/aidl_src/WVCryptoPlugin.cpp b/libwvdrmengine/mediacrypto/aidl_src/WVCryptoPlugin.cpp index d2a26ef0..3bd457d6 100644 --- a/libwvdrmengine/mediacrypto/aidl_src/WVCryptoPlugin.cpp +++ b/libwvdrmengine/mediacrypto/aidl_src/WVCryptoPlugin.cpp @@ -144,6 +144,7 @@ SharedBufferBase::~SharedBufferBase() { const char* detailedError = ""; *_aidl_return = 0; // bytes decrypted + native_handle_t* handle = nullptr; uint8_t* srcPtr = nullptr; void* destPtr = nullptr; // Convert parameters to the form the CDM wishes to consume them in. @@ -159,6 +160,7 @@ SharedBufferBase::~SharedBufferBase() { } const auto NON_SECURE = DestinationBuffer::Tag::nonsecureMemory; + const auto SECURE = DestinationBuffer::Tag::secureMemory; if (in_args.destination.getTag() == NON_SECURE) { const SharedBuffer& dest = in_args.destination.get(); if (mSharedBufferMap.find(dest.bufferId) == mSharedBufferMap.end()) { @@ -218,10 +220,8 @@ SharedBufferBase::~SharedBufferBase() { } destPtr = static_cast( dest->mBase + in_args.destination.get().offset); - } else if (in_args.destination.getTag() == - DestinationBuffer::Tag::secureMemory) { - native_handle_t* handle = android::makeFromAidl( - in_args.destination.get()); + } else if (in_args.destination.getTag() == SECURE) { + handle = android::makeFromAidl(in_args.destination.get()); destPtr = static_cast(handle); } } // lock_guard scope @@ -276,6 +276,7 @@ SharedBufferBase::~SharedBufferBase() { // Decrypt std::string errorDetailMsg; Status res = attemptDecrypt(params, hasProtectedData, &errorDetailMsg); + native_handle_delete(handle); if (res != Status::OK) { detailedError = errorDetailMsg.data(); return toNdkScopedAStatus(res, detailedError);