Skip to content

Commit

Permalink
Fix memory leak in routing_table.
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-42 committed Feb 22, 2022
1 parent d79053f commit fef260d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions libraries/http_server/http_server/dynamic_routing_table.hh
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ template <typename V> struct drt_node {
if (it != children_.end())
return children_[k]->find_or_create(r, c);
else {
auto new_node = new drt_node();
children_.insert({k, new_node});
auto new_node = std::make_shared<drt_node>();
children_shared_pointers_.push_back(new_node);
children_.insert({k, new_node.get()});
return new_node->find_or_create(r, c);
}

Expand Down Expand Up @@ -101,6 +102,7 @@ template <typename V> struct drt_node {

V v_;
std::unordered_map<std::string_view, drt_node*> children_;
std::vector<std::shared_ptr<drt_node>> children_shared_pointers_;
};
} // namespace internal

Expand Down
6 changes: 4 additions & 2 deletions single_headers/lithium.hh
Original file line number Diff line number Diff line change
Expand Up @@ -6369,8 +6369,9 @@ template <typename V> struct drt_node {
if (it != children_.end())
return children_[k]->find_or_create(r, c);
else {
auto new_node = new drt_node();
children_.insert({k, new_node});
auto new_node = std::make_shared<drt_node>();
children_shared_pointers_.push_back(new_node);
children_.insert({k, new_node.get()});
return new_node->find_or_create(r, c);
}

Expand Down Expand Up @@ -6429,6 +6430,7 @@ template <typename V> struct drt_node {

V v_;
std::unordered_map<std::string_view, drt_node*> children_;
std::vector<std::shared_ptr<drt_node>> children_shared_pointers_;
};
} // namespace internal

Expand Down
6 changes: 4 additions & 2 deletions single_headers/lithium_http_server.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3189,8 +3189,9 @@ template <typename V> struct drt_node {
if (it != children_.end())
return children_[k]->find_or_create(r, c);
else {
auto new_node = new drt_node();
children_.insert({k, new_node});
auto new_node = std::make_shared<drt_node>();
children_shared_pointers_.push_back(new_node);
children_.insert({k, new_node.get()});
return new_node->find_or_create(r, c);
}

Expand Down Expand Up @@ -3249,6 +3250,7 @@ template <typename V> struct drt_node {

V v_;
std::unordered_map<std::string_view, drt_node*> children_;
std::vector<std::shared_ptr<drt_node>> children_shared_pointers_;
};
} // namespace internal

Expand Down

0 comments on commit fef260d

Please sign in to comment.