Skip to content

Commit

Permalink
fix memory leak when error happens when initilizing rendezvous (#2784)
Browse files Browse the repository at this point in the history
  • Loading branch information
gjc13 authored Sep 24, 2020
1 parent 354ef15 commit 5d54534
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 5d54534

Please sign in to comment.