From 58fd10ad1f697bd7541ca6f58a46e235db1378ae Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Tue, 6 Sep 2022 15:57:58 +0200 Subject: [PATCH] =?UTF-8?q?Remove=20a=20leak=20when=20quit()=20is=20used?= =?UTF-8?q?=20in=20interactive=20mode,=20the=20buffer=20hol=E2=80=A6=20(#2?= =?UTF-8?q?2371)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove a leak when quit() is used in interactive mode, the buffer holding the command not beeing freed * Apply suggestions from code review Co-authored-by: Boris Zbarsky --- .../chip-tool/commands/interactive/InteractiveCommands.cpp | 6 ++++++ .../commands/interactive/InteractiveCommands.mm | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/examples/chip-tool/commands/interactive/InteractiveCommands.cpp b/examples/chip-tool/commands/interactive/InteractiveCommands.cpp index 38e706b119e056..380a6e34c6ab6c 100644 --- a/examples/chip-tool/commands/interactive/InteractiveCommands.cpp +++ b/examples/chip-tool/commands/interactive/InteractiveCommands.cpp @@ -81,6 +81,12 @@ CHIP_ERROR InteractiveStartCommand::RunCommand() } } + if (command != nullptr) + { + free(command); + command = nullptr; + } + SetCommandExitStatus(CHIP_NO_ERROR); return CHIP_NO_ERROR; } diff --git a/examples/darwin-framework-tool/commands/interactive/InteractiveCommands.mm b/examples/darwin-framework-tool/commands/interactive/InteractiveCommands.mm index 5ece0a85a227f6..7fe2d7d236d933 100644 --- a/examples/darwin-framework-tool/commands/interactive/InteractiveCommands.mm +++ b/examples/darwin-framework-tool/commands/interactive/InteractiveCommands.mm @@ -127,6 +127,11 @@ el_status_t StopFunction() } } + if (command != nullptr) { + free(command); + command = nullptr; + } + SetCommandExitStatus(CHIP_NO_ERROR); return CHIP_NO_ERROR; }