From 4237ed70b2a41b585f79f2b5d12e96193743342d Mon Sep 17 00:00:00 2001 From: "arty.ho" Date: Thu, 3 May 2018 10:55:16 +0800 Subject: [PATCH] Allocate new native handle to store sidebandStream When we get sidebandStream from TvInput, we only store the address of native handle, the address point to native_handle_t in _hidl_replay. After openStream is finished, the _hidl_replay will be freed automatically, therefore we will use the freed memory in setSidebandStrem, It will cause the writeNativeHandle fail in setSidebandStrem. Change-Id: Idd2e8343670ef5a3048836f1db978cd7c04378b7 --- services/core/jni/com_android_server_tv_TvInputHal.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/services/core/jni/com_android_server_tv_TvInputHal.cpp b/services/core/jni/com_android_server_tv_TvInputHal.cpp index 93c4829568f9e..6c2a894a3a6af 100644 --- a/services/core/jni/com_android_server_tv_TvInputHal.cpp +++ b/services/core/jni/com_android_server_tv_TvInputHal.cpp @@ -390,7 +390,11 @@ int JTvInputHal::addOrUpdateStream(int deviceId, int streamId, const sp [&result, &sidebandStream](Result res, const native_handle_t* handle) { result = res; if (res == Result::OK) { - sidebandStream = handle; + if (handle) { + sidebandStream = native_handle_clone(handle); + } else { + result = Result::UNKNOWN; + } } }); if (result != Result::OK) { @@ -398,7 +402,7 @@ int JTvInputHal::addOrUpdateStream(int deviceId, int streamId, const sp result); return UNKNOWN_ERROR; } - connection.mSourceHandle = NativeHandle::create((native_handle_t*)sidebandStream, false); + connection.mSourceHandle = NativeHandle::create((native_handle_t*)sidebandStream, true); } connection.mSurface = surface; if (connection.mSurface != nullptr) {