From 8830a42e44725afa17eaf47b50702a3758f5f575 Mon Sep 17 00:00:00 2001 From: Joonhaeng Heo Date: Fri, 6 Dec 2024 10:56:20 +0900 Subject: [PATCH] Fix memory leakage in android diag Class --- .github/workflows/java-tests.yaml | 3 --- .../java/AndroidLogDownloadFromNode.cpp | 23 +++++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.github/workflows/java-tests.yaml b/.github/workflows/java-tests.yaml index c7730f2c27b32d..c05a942a4c43eb 100644 --- a/.github/workflows/java-tests.yaml +++ b/.github/workflows/java-tests.yaml @@ -260,9 +260,6 @@ jobs: --factoryreset \ ' - name: Run Pairing Onnetwork and get diagnostic log Test - # TODO: test below is disabled because it seems flaky (crashes on pool not being empty on app exit) - # See: https://github.com/project-chip/connectedhomeip/issues/36734 - if: false run: | scripts/run_in_python_env.sh out/venv \ './scripts/tests/run_java_test.py \ diff --git a/src/controller/java/AndroidLogDownloadFromNode.cpp b/src/controller/java/AndroidLogDownloadFromNode.cpp index d37f1b727e7ed3..369d67fd714f73 100644 --- a/src/controller/java/AndroidLogDownloadFromNode.cpp +++ b/src/controller/java/AndroidLogDownloadFromNode.cpp @@ -217,22 +217,27 @@ void AndroidLogDownloadFromNode::FinishLogDownloadFromNode(CHIP_ERROR err) // Java method signature : boolean onSuccess(int fabricIndex, long nodeId) jniErr = JniReferences::GetInstance().FindMethod(env, mJavaCallback.ObjectRef(), "onSuccess", "(IJ)V", &onSuccessMethod); - VerifyOrReturn(jniErr == CHIP_NO_ERROR, ChipLogError(Controller, "Could not find onSuccess method")); + VerifyOrExit(jniErr == CHIP_NO_ERROR, ChipLogError(Controller, "Could not find onSuccess method")); env->CallVoidMethod(mJavaCallback.ObjectRef(), onSuccessMethod, static_cast(mController->GetFabricIndex()), static_cast(mRemoteNodeId)); - return; } + else + { + ChipLogError(Controller, "Log Download Failed : %" CHIP_ERROR_FORMAT, err.Format()); - ChipLogError(Controller, "Log Download Failed : %" CHIP_ERROR_FORMAT, err.Format()); + jmethodID onErrorMethod; + // Java method signature : void onError(int fabricIndex, long nodeId, long errorCode) + jniErr = JniReferences::GetInstance().FindMethod(env, mJavaCallback.ObjectRef(), "onError", "(IJJ)V", &onErrorMethod); + VerifyOrExit(jniErr == CHIP_NO_ERROR, ChipLogError(Controller, "Could not find onError method")); - jmethodID onErrorMethod; - // Java method signature : void onError(int fabricIndex, long nodeId, long errorCode) - jniErr = JniReferences::GetInstance().FindMethod(env, mJavaCallback.ObjectRef(), "onError", "(IJJ)V", &onErrorMethod); - VerifyOrReturn(jniErr == CHIP_NO_ERROR, ChipLogError(Controller, "Could not find onError method")); + env->CallVoidMethod(mJavaCallback.ObjectRef(), onErrorMethod, static_cast(mController->GetFabricIndex()), + static_cast(mRemoteNodeId), static_cast(err.AsInteger())); + } - env->CallVoidMethod(mJavaCallback.ObjectRef(), onErrorMethod, static_cast(mController->GetFabricIndex()), - static_cast(mRemoteNodeId), static_cast(err.AsInteger())); +exit: + // Finish this function, this object will be deleted. + delete this; } void AndroidLogDownloadFromNode::OnBdxTransferCallback(void * context, FabricIndex fabricIndex, NodeId remoteNodeId,