C2: Delete mHandle properly to avoid memory leakage
The return in the destructor of C2AllocationGralloc make its mHandle
cannot be deleted properly. Remove the return and add the check for each
resource properly to ensure mHandle can be freed.
Bug: 119925123
Test: Play Youtube without increase inside memory heap
Change-Id: Ifd4f1e405a30b9993082237d6a62b8a60c0cda20
diff --git a/media/codec2/vndk/C2AllocatorGralloc.cpp b/media/codec2/vndk/C2AllocatorGralloc.cpp
index 4878974..fdea2d3 100644
--- a/media/codec2/vndk/C2AllocatorGralloc.cpp
+++ b/media/codec2/vndk/C2AllocatorGralloc.cpp
@@ -304,17 +304,18 @@
}
C2AllocationGralloc::~C2AllocationGralloc() {
- if (!mBuffer) {
- return;
- }
- if (mLocked) {
+ if (mBuffer && mLocked) {
// implementation ignores addresss and rect
uint8_t* addr[C2PlanarLayout::MAX_NUM_PLANES] = {};
unmap(addr, C2Rect(), nullptr);
}
- mMapper->freeBuffer(const_cast<native_handle_t *>(mBuffer));
- native_handle_delete(const_cast<native_handle_t*>(
- reinterpret_cast<const native_handle_t*>(mHandle)));
+ if (mBuffer) {
+ mMapper->freeBuffer(const_cast<native_handle_t *>(mBuffer));
+ }
+ if (mHandle) {
+ native_handle_delete(
+ const_cast<native_handle_t *>(reinterpret_cast<const native_handle_t *>(mHandle)));
+ }
}
c2_status_t C2AllocationGralloc::map(