Remove a leak when quit() is used in interactive mode, the buffer hol… (#22371)

* 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 <bzbarsky@apple.com>
diff --git a/examples/chip-tool/commands/interactive/InteractiveCommands.cpp b/examples/chip-tool/commands/interactive/InteractiveCommands.cpp
index 38e706b..380a6e3 100644
--- a/examples/chip-tool/commands/interactive/InteractiveCommands.cpp
+++ b/examples/chip-tool/commands/interactive/InteractiveCommands.cpp
@@ -81,6 +81,12 @@
         }
     }
 
+    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 5ece0a8..7fe2d7d 100644
--- a/examples/darwin-framework-tool/commands/interactive/InteractiveCommands.mm
+++ b/examples/darwin-framework-tool/commands/interactive/InteractiveCommands.mm
@@ -127,6 +127,11 @@
         }
     }
 
+    if (command != nullptr) {
+        free(command);
+        command = nullptr;
+    }
+
     SetCommandExitStatus(CHIP_NO_ERROR);
     return CHIP_NO_ERROR;
 }