Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Unified Diff: ui/gfx/geometry/r_tree.cc

Issue 270373002: fix leak in RTree::Remove() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixing nit Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/geometry/r_tree.cc
diff --git a/ui/gfx/geometry/r_tree.cc b/ui/gfx/geometry/r_tree.cc
index e62e546b92d013d342108f12e123520758f9980d..00e75eb4d0d1de078af32f846db25dcd92a34cbb 100644
--- a/ui/gfx/geometry/r_tree.cc
+++ b/ui/gfx/geometry/r_tree.cc
@@ -627,8 +627,7 @@ void RTree::Remove(intptr_t key) {
// Lastly check the root. If it has only one non-leaf child, delete it and
// replace it with its child.
if (root_->count() == 1 && root_->level() > 0) {
- scoped_ptr<Node> new_root(root_->RemoveAndReturnLastChild());
- root_.swap(new_root);
+ root_ = root_->RemoveAndReturnLastChild();
}
}
@@ -716,10 +715,14 @@ void RTree::RemoveNode(Node* node) {
// Traverse up the tree, removing the child from each parent and deleting
// parent nodes, until we either encounter the root of the tree or a parent
// that still has sufficient children.
- while (parent && parent->RemoveChild(child, &orphans) < min_children_) {
- if (child != node) {
+ while (parent) {
+ size_t children_remaining = parent->RemoveChild(child, &orphans);
+ if (child != node)
delete child;
- }
+
+ if (children_remaining >= min_children_)
+ break;
+
child = parent;
parent = parent->parent();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698