mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 07:43:01 +01:00
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.
This commit is contained in:
@@ -1730,10 +1730,10 @@ void InteractiveConsole::Execute(const std::string& s)
|
||||
start = end;
|
||||
} while (*end != 0);
|
||||
|
||||
if (argc == 0)
|
||||
return;
|
||||
|
||||
bool validCommand = false;
|
||||
|
||||
if (argc > 0)
|
||||
{
|
||||
for (const auto& c : console_command_table)
|
||||
{
|
||||
if (strcmp(argv[0], c.command) == 0)
|
||||
@@ -1743,12 +1743,13 @@ void InteractiveConsole::Execute(const std::string& s)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < argc; i++)
|
||||
free(argv[i]);
|
||||
free(argv);
|
||||
|
||||
if (!validCommand)
|
||||
if (argc > 0 && !validCommand)
|
||||
{
|
||||
WriteLineError("Unknown command. Type help to list available commands.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user