From 5d545345b71338b97729e2218e0fc8b3d70811f7 Mon Sep 17 00:00:00 2001 From: Jiacheng Guo Date: Fri, 25 Sep 2020 01:45:10 +0800 Subject: [PATCH] fix memory leak when error happens when initilizing rendezvous (#2784) --- src/controller/CHIPDeviceController.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index a26a3c8d1f1ea0..8e8f47c12f5587 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -151,8 +151,8 @@ CHIP_ERROR ChipDeviceController::ConnectDevice(NodeId remoteDeviceId, Rendezvous NewConnectionHandler onConnected, MessageReceiveHandler onMessageReceived, ErrorHandler onError) { - CHIP_ERROR err = CHIP_NO_ERROR; - RendezvousSession * rendezvousSession; + CHIP_ERROR err = CHIP_NO_ERROR; + RendezvousSession * rendezvousSession = nullptr; VerifyOrExit(mState == kState_Initialized, err = CHIP_ERROR_INCORRECT_STATE); VerifyOrExit(mConState == kConnectionState_NotConnected, err = CHIP_ERROR_INCORRECT_STATE); @@ -181,6 +181,11 @@ CHIP_ERROR ChipDeviceController::ConnectDevice(NodeId remoteDeviceId, Rendezvous mOnError = onError; exit: + if (err != CHIP_NO_ERROR && rendezvousSession != nullptr) + { + delete rendezvousSession; + } + return err; }