Skip to content

Commit 8830a42

Browse files
committed
Fix memory leakage in android diag Class
1 parent c2739ca commit 8830a42

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

.github/workflows/java-tests.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,6 @@ jobs:
260260
--factoryreset \
261261
'
262262
- name: Run Pairing Onnetwork and get diagnostic log Test
263-
# TODO: test below is disabled because it seems flaky (crashes on pool not being empty on app exit)
264-
# See: https://github.com/project-chip/connectedhomeip/issues/36734
265-
if: false
266263
run: |
267264
scripts/run_in_python_env.sh out/venv \
268265
'./scripts/tests/run_java_test.py \

src/controller/java/AndroidLogDownloadFromNode.cpp

+14-9
Original file line numberDiff line numberDiff line change
@@ -217,22 +217,27 @@ void AndroidLogDownloadFromNode::FinishLogDownloadFromNode(CHIP_ERROR err)
217217
// Java method signature : boolean onSuccess(int fabricIndex, long nodeId)
218218
jniErr = JniReferences::GetInstance().FindMethod(env, mJavaCallback.ObjectRef(), "onSuccess", "(IJ)V", &onSuccessMethod);
219219

220-
VerifyOrReturn(jniErr == CHIP_NO_ERROR, ChipLogError(Controller, "Could not find onSuccess method"));
220+
VerifyOrExit(jniErr == CHIP_NO_ERROR, ChipLogError(Controller, "Could not find onSuccess method"));
221221

222222
env->CallVoidMethod(mJavaCallback.ObjectRef(), onSuccessMethod, static_cast<jint>(mController->GetFabricIndex()),
223223
static_cast<jlong>(mRemoteNodeId));
224-
return;
225224
}
225+
else
226+
{
227+
ChipLogError(Controller, "Log Download Failed : %" CHIP_ERROR_FORMAT, err.Format());
226228

227-
ChipLogError(Controller, "Log Download Failed : %" CHIP_ERROR_FORMAT, err.Format());
229+
jmethodID onErrorMethod;
230+
// Java method signature : void onError(int fabricIndex, long nodeId, long errorCode)
231+
jniErr = JniReferences::GetInstance().FindMethod(env, mJavaCallback.ObjectRef(), "onError", "(IJJ)V", &onErrorMethod);
232+
VerifyOrExit(jniErr == CHIP_NO_ERROR, ChipLogError(Controller, "Could not find onError method"));
228233

229-
jmethodID onErrorMethod;
230-
// Java method signature : void onError(int fabricIndex, long nodeId, long errorCode)
231-
jniErr = JniReferences::GetInstance().FindMethod(env, mJavaCallback.ObjectRef(), "onError", "(IJJ)V", &onErrorMethod);
232-
VerifyOrReturn(jniErr == CHIP_NO_ERROR, ChipLogError(Controller, "Could not find onError method"));
234+
env->CallVoidMethod(mJavaCallback.ObjectRef(), onErrorMethod, static_cast<jint>(mController->GetFabricIndex()),
235+
static_cast<jlong>(mRemoteNodeId), static_cast<jlong>(err.AsInteger()));
236+
}
233237

234-
env->CallVoidMethod(mJavaCallback.ObjectRef(), onErrorMethod, static_cast<jint>(mController->GetFabricIndex()),
235-
static_cast<jlong>(mRemoteNodeId), static_cast<jlong>(err.AsInteger()));
238+
exit:
239+
// Finish this function, this object will be deleted.
240+
delete this;
236241
}
237242

238243
void AndroidLogDownloadFromNode::OnBdxTransferCallback(void * context, FabricIndex fabricIndex, NodeId remoteNodeId,

0 commit comments

Comments
 (0)