From 24f18983923cc63706e3c5c8a5db6bb073e7afb7 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 9 Jul 2018 22:05:53 +0300 Subject: Fix memory leak due to complement repository cycles --- bpkg/rep-remove.cxx | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'bpkg/rep-remove.cxx') diff --git a/bpkg/rep-remove.cxx b/bpkg/rep-remove.cxx index c070418..5a7f8da 100644 --- a/bpkg/rep-remove.cxx +++ b/bpkg/rep-remove.cxx @@ -247,15 +247,13 @@ namespace bpkg // Prior to removing a prerequisite/complement we need to make sure it // still exists, which may not be the case due to the dependency cycle. // - auto remove = [&c, &db, &t] (const lazy_shared_ptr& rp) + auto remove = [&c, &db, &t] (const lazy_weak_ptr& rp) { - shared_ptr r (db.find (rp.object_id ())); - - if (r) + if (shared_ptr r = db.find (rp.object_id ())) rep_remove (c, t, r); }; - for (const lazy_shared_ptr& cr: rf->complements) + for (const lazy_weak_ptr& cr: rf->complements) { // Remove the complement unless it is the root repository (see // rep_fetch() for details). @@ -265,7 +263,7 @@ namespace bpkg } for (const lazy_weak_ptr& pr: rf->prerequisites) - remove (lazy_shared_ptr (pr)); + remove (pr); // If there are no repositories stayed in the database then no repository // fragments nor packages should stay either. @@ -301,13 +299,13 @@ namespace bpkg query::name != ""); shared_ptr root (db.load ("")); - repository_fragment::complements_type& ua (root->complements); + repository_fragment::dependencies& ua (root->complements); for (shared_ptr r: pointer_result (db.query ())) { if (r->name == "") l5 ([&]{trace << "skipping root repository";}); - else if (ua.find (lazy_shared_ptr (db, r)) != ua.end ()) + else if (ua.find (lazy_weak_ptr (db, r)) != ua.end ()) { r->fragments.clear (); db.update (r); @@ -395,12 +393,12 @@ namespace bpkg session s; // Repository dependencies can have cycles. shared_ptr root (db.load ("")); - repository_fragment::complements_type& ua (root->complements); + repository_fragment::dependencies& ua (root->complements); if (o.all ()) { - for (const lazy_shared_ptr& r: ua) - repos.push_back (r); + for (const lazy_weak_ptr& r: ua) + repos.push_back (lazy_shared_ptr (r)); } else { @@ -435,11 +433,11 @@ namespace bpkg repository_url u (a); assert (!u.empty ()); - for (const lazy_shared_ptr& rp: ua) + for (const lazy_weak_ptr& rp: ua) { if (rp.load ()->location.url () == u) { - r = rp; + r = lazy_shared_ptr (rp); break; } } -- cgit v1.1