From ae817b6f33a4cbf41df1d297a66ccc90b299eaf9 Mon Sep 17 00:00:00 2001 From: yunhanw Date: Wed, 17 Jan 2024 00:18:31 -0800 Subject: [PATCH] Fix crash in getConnectedDevicePointer --- src/controller/java/CHIPDeviceController-JNI.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp index 9b3e67b6bf253b..a4168a62ab5b7f 100644 --- a/src/controller/java/CHIPDeviceController-JNI.cpp +++ b/src/controller/java/CHIPDeviceController-JNI.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include #include #include @@ -1360,10 +1361,16 @@ JNI_METHOD(void, getConnectedDevicePointer)(JNIEnv * env, jobject self, jlong ha AndroidDeviceControllerWrapper * wrapper = AndroidDeviceControllerWrapper::FromJNIHandle(handle); GetConnectedDeviceCallback * connectedDeviceCallback = reinterpret_cast(callbackHandle); - VerifyOrReturn(connectedDeviceCallback != nullptr, ChipLogError(Controller, "GetConnectedDeviceCallback handle is nullptr")); + VerifyOrExit(connectedDeviceCallback != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT); err = wrapper->Controller()->GetConnectedDevice(static_cast(nodeId), &connectedDeviceCallback->mOnSuccess, &connectedDeviceCallback->mOnFailure); - VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Controller, "Error invoking GetConnectedDevice")); +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(Controller, "GetConnectedDevice failed: %" CHIP_ERROR_FORMAT, err.Format()); + OperationalSessionSetup::ConnnectionFailureInfo failureInfo(chip::ScopedNodeId(static_cast(nodeId), wrapper->Controller()->GetFabricIndex()), err, SessionEstablishmentStage::kUnknown); + connectedDeviceCallback->mOnFailure.mCall(&connectedDeviceCallback->mOnFailure.mContext, failureInfo); + } } JNI_METHOD(void, releaseOperationalDevicePointer)(JNIEnv * env, jobject self, jlong devicePtr)