[Memory Leak] Fix leak of CommandRecords in commandlist (#2244)

* Fix leak of CommandRecords in commandlist

Quicker than porting to std::unique_ptr since we do fun stuff with
commandlist ...

* Fix leak so it won't double free

This is fine enough until we rewrite it to be better
This commit is contained in:
Michael Cook (mackal) 2022-06-06 15:21:35 -04:00 committed by GitHub
parent b4d5e807e3
commit 2910073373
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -52,6 +52,7 @@ int (*command_dispatch)(Client *,std::string) = command_notavail;
std::map<std::string, CommandRecord *> commandlist;
std::map<std::string, std::string> commandaliases;
std::vector<CommandRecord *> command_delete_list;
/*
* command_notavail
@ -466,6 +467,9 @@ int command_init(void)
*/
void command_deinit(void)
{
for (auto &c : command_delete_list)
delete c;
command_delete_list.clear();
commandlist.clear();
commandaliases.clear();
@ -517,6 +521,7 @@ int command_add(std::string command_name, std::string description, uint8 admin,
commandlist[command_name] = c;
commandaliases[command_name] = command_name;
command_delete_list.push_back(c);
command_count++;
return 0;