From ef546db381280f1f7097a4e39abe91b85b827dff Mon Sep 17 00:00:00 2001 From: Chih-Yu Huang Date: Thu, 11 Mar 2021 14:37:21 +0900 Subject: [PATCH] Close the handle returned by WrapNativeCodec2GrallocHandle() At ag/13824423 we fixed the description of WrapNativeCodec2GrallocHandle() that the returned handle should be closed and deleted. This CL closes and deletes the handle if the ownership of the returned handle is not transfered to C2GraphicAllocation successfully. Bug: 181541291 Test: android.media.cts.AdaptivePlaybackTest Change-Id: I18464f860a93a750db653eb615ae0c92a672535e --- media/jni/android_media_MediaCodec.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/media/jni/android_media_MediaCodec.cpp b/media/jni/android_media_MediaCodec.cpp index 1870a939f0dc6..7f5dd5d15dbec 100644 --- a/media/jni/android_media_MediaCodec.cpp +++ b/media/jni/android_media_MediaCodec.cpp @@ -2260,6 +2260,8 @@ static void android_media_MediaCodec_native_queueHardwareBuffer( c2_status_t c2err = sGrallocAlloc->priorGraphicAllocation(handle, &alloc); if (c2err != C2_OK) { ALOGW("Failed to wrap AHardwareBuffer into C2GraphicAllocation"); + native_handle_close(handle); + native_handle_delete(handle); throwExceptionAsNecessary(env, BAD_VALUE); return; }