diff --git a/ui/views/view.cc b/ui/views/view.cc index ab2fe0fbefc4c..6cf3300f20df1 100644 --- a/ui/views/view.cc +++ b/ui/views/view.cc @@ -3761,7 +3761,16 @@ bool View::UpdateParentLayers() { void View::OrphanLayers() { if (layer()) { if (ui::Layer* parent = layer()->parent()) { + // Layer::Remove() synchronously calls StopAnimatingProperty(BOUNDS), + // which may fire LayerAnimationObserver callbacks that destroy + // `parent` (see crbug.com/1088432, where Layer::Remove() grew an inner + // weak_this guard for the same hazard). Mirror that guard at the outer + // loop so a later iteration does not dereference a freed `parent`. + base::WeakPtr weak_parent = parent->AsWeakPtr(); for (ui::Layer* layer : GetLayersInOrder()) { + if (!weak_parent) { + break; + } // TODO(http://b/319941708): Please remove the below crash keys once the // the crash is fixed. It seems one of the layers returned by // `GetLayersInOrder()` is not a sibling of this view's `layer()` (i.e.