Close the handle returned by WrapNativeCodec2GrallocHandle()
WrapNativeCodec2GrallocHandle() creates a new native handle, and
clones the fd of the input native handle. The caller should explicitly
close and delete the returned native handle.
This CL updates the description of WrapNativeCodec2GrallocHandle(),
and calls native_handle_close() and native_handle_delete() if the
ownership of the returned handle is not transfered to
C2GraphicAllocation successfully.
Bug: 181541291
Test: android.media.cts.AdaptivePlaybackTest
Change-Id: I53726b61115a212675a199ddcd843df1fead948c
diff --git a/media/codec2/hidl/1.0/utils/InputSurfaceConnection.cpp b/media/codec2/hidl/1.0/utils/InputSurfaceConnection.cpp
index 5ec88ec..7c2e014 100644
--- a/media/codec2/hidl/1.0/utils/InputSurfaceConnection.cpp
+++ b/media/codec2/hidl/1.0/utils/InputSurfaceConnection.cpp
@@ -201,6 +201,8 @@
c2_status_t err = mAllocator->priorGraphicAllocation(handle, &alloc);
mAllocatorMutex.unlock();
if (err != OK) {
+ native_handle_close(handle);
+ native_handle_delete(handle);
return UNKNOWN_ERROR;
}
std::shared_ptr<C2GraphicBlock> block =
diff --git a/media/codec2/sfplugin/C2OMXNode.cpp b/media/codec2/sfplugin/C2OMXNode.cpp
index ab73245..3a7af10 100644
--- a/media/codec2/sfplugin/C2OMXNode.cpp
+++ b/media/codec2/sfplugin/C2OMXNode.cpp
@@ -392,6 +392,8 @@
if (err != OK) {
(void)fd0.release();
(void)fd1.release();
+ native_handle_close(handle);
+ native_handle_delete(handle);
return UNKNOWN_ERROR;
}
block = _C2BlockFactory::CreateGraphicBlock(alloc);
diff --git a/media/codec2/sfplugin/Codec2Buffer.cpp b/media/codec2/sfplugin/Codec2Buffer.cpp
index fc4ee51..34e6a88 100644
--- a/media/codec2/sfplugin/Codec2Buffer.cpp
+++ b/media/codec2/sfplugin/Codec2Buffer.cpp
@@ -713,6 +713,8 @@
c2_status_t err = mAlloc->priorGraphicAllocation(handle, &alloc);
if (err != C2_OK) {
ALOGD("Failed to wrap VideoNativeMetadata into C2GraphicAllocation");
+ native_handle_close(handle);
+ native_handle_delete(handle);
return nullptr;
}
std::shared_ptr<C2GraphicBlock> block = _C2BlockFactory::CreateGraphicBlock(alloc);
diff --git a/media/codec2/vndk/include/C2AllocatorGralloc.h b/media/codec2/vndk/include/C2AllocatorGralloc.h
index 578cf76..1da3e14 100644
--- a/media/codec2/vndk/include/C2AllocatorGralloc.h
+++ b/media/codec2/vndk/include/C2AllocatorGralloc.h
@@ -37,7 +37,8 @@
* Wrap the gralloc handle and metadata into Codec2 handle recognized by
* C2AllocatorGralloc.
*
- * @return a new NON-OWNING C2Handle that must be deleted using native_handle_delete.
+ * @return a new NON-OWNING C2Handle that must be closed and deleted using native_handle_close and
+ * native_handle_delete.
*/
C2Handle *WrapNativeCodec2GrallocHandle(
const native_handle_t *const handle,
diff --git a/media/codec2/vndk/platform/C2BqBuffer.cpp b/media/codec2/vndk/platform/C2BqBuffer.cpp
index e14b4b1..3f6fa7d 100644
--- a/media/codec2/vndk/platform/C2BqBuffer.cpp
+++ b/media/codec2/vndk/platform/C2BqBuffer.cpp
@@ -364,6 +364,8 @@
std::shared_ptr<C2GraphicAllocation> alloc;
c2_status_t err = mAllocator->priorGraphicAllocation(c2Handle, &alloc);
if (err != C2_OK) {
+ native_handle_close(c2Handle);
+ native_handle_delete(c2Handle);
return err;
}
std::shared_ptr<C2BufferQueueBlockPoolData> poolData =