wv aidl: fix native handle memory leak

[ Merge of go/wvgerrit/145971 ]

Bug: 219754570
Test: atest GtsMediaTestCases
Change-Id: Id4705d5bc10ba6dfbe878f2d95fdd9ae9d2e9f1d
This commit is contained in:
Robert Shih
2022-02-16 13:35:09 -08:00
parent 9654d29be6
commit eed349c158

View File

@@ -144,6 +144,7 @@ SharedBufferBase::~SharedBufferBase() {
const char* detailedError = ""; const char* detailedError = "";
*_aidl_return = 0; // bytes decrypted *_aidl_return = 0; // bytes decrypted
native_handle_t* handle = nullptr;
uint8_t* srcPtr = nullptr; uint8_t* srcPtr = nullptr;
void* destPtr = nullptr; void* destPtr = nullptr;
// Convert parameters to the form the CDM wishes to consume them in. // Convert parameters to the form the CDM wishes to consume them in.
@@ -160,6 +161,7 @@ SharedBufferBase::~SharedBufferBase() {
} }
const auto NON_SECURE = DestinationBuffer::Tag::nonsecureMemory; const auto NON_SECURE = DestinationBuffer::Tag::nonsecureMemory;
const auto SECURE = DestinationBuffer::Tag::secureMemory;
if (in_args.destination.getTag() == NON_SECURE) { if (in_args.destination.getTag() == NON_SECURE) {
const SharedBuffer& dest = in_args.destination.get<NON_SECURE>(); const SharedBuffer& dest = in_args.destination.get<NON_SECURE>();
if (mSharedBufferMap.find(dest.bufferId) == mSharedBufferMap.end()) { if (mSharedBufferMap.find(dest.bufferId) == mSharedBufferMap.end()) {
@@ -219,10 +221,8 @@ SharedBufferBase::~SharedBufferBase() {
} }
destPtr = static_cast<void*>( destPtr = static_cast<void*>(
dest->mBase + in_args.destination.get<NON_SECURE>().offset); dest->mBase + in_args.destination.get<NON_SECURE>().offset);
} else if (in_args.destination.getTag() == } else if (in_args.destination.getTag() == SECURE) {
DestinationBuffer::Tag::secureMemory) { handle = android::makeFromAidl(in_args.destination.get<SECURE>());
native_handle_t* handle = android::makeFromAidl(
in_args.destination.get<DestinationBuffer::Tag::secureMemory>());
destPtr = static_cast<void*>(handle); destPtr = static_cast<void*>(handle);
} }
} // lock_guard scope } // lock_guard scope
@@ -277,6 +277,7 @@ SharedBufferBase::~SharedBufferBase() {
// Decrypt // Decrypt
std::string errorDetailMsg; std::string errorDetailMsg;
Status res = attemptDecrypt(params, hasProtectedData, &errorDetailMsg); Status res = attemptDecrypt(params, hasProtectedData, &errorDetailMsg);
native_handle_delete(handle);
if (res != Status::OK) { if (res != Status::OK) {
detailedError = errorDetailMsg.data(); detailedError = errorDetailMsg.data();
return toNdkScopedAStatus(res, detailedError); return toNdkScopedAStatus(res, detailedError);