Merge "wv aidl: fix native handle memory leak"

This commit is contained in:
Robert Shih
2022-02-17 23:46:55 +00:00
committed by Android (Google) Code Review

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.
@@ -159,6 +160,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()) {
@@ -218,10 +220,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
@@ -276,6 +276,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);