From 55af6ad0e1ba61eff683dfa5ca17e5f67e5babbc Mon Sep 17 00:00:00 2001 From: Tom Lankhorst Date: Tue, 22 Jan 2019 00:03:12 +0100 Subject: [PATCH] Free allocated memory when 'argc' == 0 (#8619) Fixes leak in #8597, InteractiveConsole allocates memory for arguments, but frees it only if the argument count is greater than zero. --- src/openrct2/interface/InteractiveConsole.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index 9354160107..8e740f1873 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -1730,17 +1730,18 @@ void InteractiveConsole::Execute(const std::string& s) start = end; } while (*end != 0); - if (argc == 0) - return; - bool validCommand = false; - for (const auto& c : console_command_table) + + if (argc > 0) { - if (strcmp(argv[0], c.command) == 0) + for (const auto& c : console_command_table) { - c.func(*this, (const utf8**)(argv + 1), argc - 1); - validCommand = true; - break; + if (strcmp(argv[0], c.command) == 0) + { + c.func(*this, (const utf8**)(argv + 1), argc - 1); + validCommand = true; + break; + } } } @@ -1748,7 +1749,7 @@ void InteractiveConsole::Execute(const std::string& s) free(argv[i]); free(argv); - if (!validCommand) + if (argc > 0 && !validCommand) { WriteLineError("Unknown command. Type help to list available commands."); }