fix: leak mitigations

This commit is contained in:
3lswear
2022-02-06 19:01:52 +03:00
parent b2df81d00d
commit 81320af92e
2 changed files with 37 additions and 14 deletions

View File

@@ -281,7 +281,6 @@ void Server::clean_generic(toml_node *node)
{ {
DBOUT << "cleaning string" << ENDL; DBOUT << "cleaning string" << ENDL;
delete node->getString(); delete node->getString();
delete node;
} }
break; break;
case toml_node::MAPARRAY: case toml_node::MAPARRAY:
@@ -291,13 +290,21 @@ void Server::clean_generic(toml_node *node)
for (TOMLMapArray::iterator it = map_array->begin(); for (TOMLMapArray::iterator it = map_array->begin();
it != map_array->end(); ++it) it != map_array->end(); ++it)
{ {
DBOUT << "cleaning a MAP of MAPARRAY" << ENDL;
TOMLMap *map = *it; TOMLMap *map = *it;
for (TOMLMap::iterator map_it = map->begin(); TOMLMap::iterator map_it = map->begin();
for (map_it = map->begin();
map_it != map->end(); ++map_it) map_it != map->end(); ++map_it)
{ {
DBOUT << "cleaning a MAP item " << map_it->first << ENDL;
clean_generic(map_it->second); clean_generic(map_it->second);
/* map->erase(map_it); */
} }
map->clear();
delete map;
} }
map_array->clear();
delete map_array;
DBOUT << "end cleaning MAPARRAY" << ENDL; DBOUT << "end cleaning MAPARRAY" << ENDL;
} }
break; break;
@@ -309,20 +316,34 @@ void Server::clean_generic(toml_node *node)
{ {
DBOUT << "key is " << it->first << ENDL; DBOUT << "key is " << it->first << ENDL;
clean_generic(it->second); clean_generic(it->second);
map->erase(it); /* map->erase(it); */
} }
map->clear(); map->clear();
delete node; delete map;
}
break;
case toml_node::ARRAY:
{
DBOUT << "cleaning ARRAY" << ENDL;
TOMLArray *arr = node->getArray();
for (TOMLArray::iterator it = arr->begin();
it != arr->end(); ++it)
{
clean_generic(*it);
}
arr->clear();
delete arr;
DBOUT << "end cleaning MAP" << ENDL; DBOUT << "end cleaning MAP" << ENDL;
} }
break; break;
default: default:
{ {
DBOUT << "Cleaning " << node->type << " not implemented :)" << ENDL; DBOUT << "Cleaning type " << node->type << " not implemented :)" << ENDL;
delete node;
} }
} }
delete node;
} }
@@ -333,16 +354,17 @@ void Server::clean_parsed(TOMLMap *root)
DBOUT << ">>> cleaning up: <<<" << std::endl; DBOUT << ">>> cleaning up: <<<" << std::endl;
for (it = root->begin(); it != root->end(); ++it) for (it = root->begin(); it != root->end(); ++it)
{ {
DBOUT << RED << it->first /* DBOUT << RED << it->first */
<< ": " << GREEN /* << ": " << GREEN */
<< *(it->second->toString()); /* << *(it->second->toString()); */
clean_generic(it->second); clean_generic(it->second);
/* delete it->second; */ /* delete it->second; */
std::cout << ", " << std::endl; std::cout << ", " << std::endl;
} }
DBOUT << YELLO << "end of clean" << ENDL; DBOUT << YELLO << "end of clean" << ENDL;
/* delete root; */ root->clear();
delete root;
root = NULL; root = NULL;
} }

View File

@@ -444,6 +444,7 @@ namespace config
} }
else else
(it->second)->getMapArray()->push_back(map_node->getMap()); (it->second)->getMapArray()->push_back(map_node->getMap());
delete map_node;
} }
else if (type == toml_node::MAP) else if (type == toml_node::MAP)
{ {
@@ -460,13 +461,13 @@ namespace config
{ {
it = local_root->find(*subname); it = local_root->find(*subname);
toml_node *map_node2;
map_node2 = new toml_node;
TOMLMap *map = new TOMLMap;
map_node2->setObject(map);
/* subname not found in local_root */ /* subname not found in local_root */
if (it == local_root->end()) if (it == local_root->end())
{ {
toml_node *map_node2;
map_node2 = new toml_node;
TOMLMap *map = new TOMLMap;
map_node2->setObject(map);
(*local_root)[*subname] = map_node2; (*local_root)[*subname] = map_node2;
local_root = map; local_root = map;
} }