From 44a59499ea3d629e5121798a796b24ac962ca6f7 Mon Sep 17 00:00:00 2001 From: Akhila musunuri Date: Thu, 21 Jul 2016 13:33:11 +0530 Subject: [PATCH] CameraJNI: Fix memory leak in stop recording. Issue: Due to race conditions, if a recording frame callback is received after a proxy listener is set to NULL, the callback is forwarded to JNIContext which does nothing. This will lead to buffer leak in metadata mode because fd would have been duped already. Fix: Release recording frame from JNIContext. Bug: 30299751 CRs-Fixed: 1040448 Change-Id: I315ec3124014c6309d68fdc1be1e18091a84e154 Bug : 30143478 --- core/jni/android_hardware_Camera.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/core/jni/android_hardware_Camera.cpp b/core/jni/android_hardware_Camera.cpp index 94592573e61ad..b926270100598 100644 --- a/core/jni/android_hardware_Camera.cpp +++ b/core/jni/android_hardware_Camera.cpp @@ -350,9 +350,16 @@ void JNICameraContext::postDataTimestamp(nsecs_t timestamp, int32_t msgType, con postData(msgType, dataPtr, NULL); } -void JNICameraContext::postRecordingFrameHandleTimestamp(nsecs_t, native_handle_t*) { - // This is not needed at app layer. This should not be called because JNICameraContext cannot - // start video recording. +void JNICameraContext::postRecordingFrameHandleTimestamp(nsecs_t, native_handle_t* handle) { + // Video buffers are not needed at app layer so just return the video buffers here. + // This may be called when stagefright just releases camera but there are still outstanding + // video buffers. + if (mCamera != nullptr) { + mCamera->releaseRecordingFrameHandle(handle); + } else { + native_handle_close(handle); + native_handle_delete(handle); + } } void JNICameraContext::postMetadata(JNIEnv *env, int32_t msgType, camera_frame_metadata_t *metadata)