Repository: flutter
Issue: SkSurfaces from Embedder backing stores may not be collected on engine shutdown.
Labels: engine,from: sanitizer,P2,team-engine,triaged-engine

Caught by Leak Sanitizer in the `embedder_unittests` target.

```
Direct leak of 48 byte(s) in 3 object(s) allocated from:
    #0 0x113a5b522 in wrap__Znwm (libclang_rt.asan_osx_dynamic.dylib:x86_64+0x66522)
    #1 0x10600595d in std::__1::__unique_if<MakeSkSurfaceFromBackingStore(GrContext*, FlutterBackingStoreConfig const&, FlutterSoftwareBackingStore const*)::Captures>::__unique_single std::__1::make_unique<MakeSkSurfaceFromBackingStore(GrContext*, FlutterBackingStoreConfig const&, FlutterSoftwareBackingStore const*)::Captures>() memory:3118
    #2 0x105ffed36 in MakeSkSurfaceFromBackingStore(GrContext*, FlutterBackingStoreConfig const&, FlutterSoftwareBackingStore const*) embedder.cc:377
    #3 0x105ffd043 in CreateEmbedderRenderTarget(FlutterCompositor const*, FlutterBackingStoreConfig const&, GrContext*) embedder.cc:452
    #4 0x105ffc499 in auto InferExternalViewEmbedderFromArgs(FlutterCompositor const*)::$_2::operator()<FlutterBackingStoreConfig>(GrContext*, FlutterBackingStoreConfig const&) const embedder.cc:492
    #5 0x105ffc3d9 in decltype(std::__1::forward<InferExternalViewEmbedderFromArgs(FlutterCompositor const*)::$_2&>(fp)(std::__1::forward<GrContext*>(fp0), std::__1::forward<FlutterBackingStoreConfig const&>(fp0))) std::__1::__invoke<InferExternalViewEmbedderFromArgs(FlutterCompositor const*)::$_2&, GrContext*, FlutterBackingStoreConfig const&>(InferExternalViewEmbedderFromArgs(FlutterCompositor const*)::$_2&&&, GrContext*&&, FlutterBackingStoreConfig const&&&) type_traits:4350
    #6 0x105ffc266 in std::__1::unique_ptr<flutter::EmbedderRenderTarget, std::__1::default_delete<flutter::EmbedderRenderTarget> > std::__1::__invoke_void_return_wrapper<std::__1::unique_ptr<flutter::EmbedderRenderTarget, std::__1::default_delete<flutter::EmbedderRenderTarget> > >::__call<InferExternalViewEmbedderFromArgs(FlutterCompositor const*)::$_2&, GrContext*, FlutterBackingStoreConfig const&>(InferExternalViewEmbedderFromArgs(FlutterCompositor const*)::$_2&&&, GrContext*&&, FlutterBackingStoreConfig const&&&) __functional_base:318
    #7 0x105ff89fa in std::__1::__function::__func<InferExternalViewEmbedderFromArgs(FlutterCompositor const*)::$_2, std::__1::allocator<InferExternalViewEmbedderFromArgs(FlutterCompositor const*)::$_2>, std::__1::unique_ptr<flutter::EmbedderRenderTarget, std::__1::default_delete<flutter::EmbedderRenderTarget> > (GrContext*, FlutterBackingStoreConfig const&)>::operator()(GrContext*&&, FlutterBackingStoreConfig const&) functional:1572
    #8 0x1060ba6c5 in std::__1::function<std::__1::unique_ptr<flutter::EmbedderRenderTarget, std::__1::default_delete<flutter::EmbedderRenderTarget> > (GrContext*, FlutterBackingStoreConfig const&)>::operator()(GrContext*, FlutterBackingStoreConfig const&) const functional:1923
    #9 0x1060c0690 in flutter::EmbedderExternalViewEmbedder::SubmitFrame(GrContext*) embedder_external_view_embedder.cc:286
    #10 0x109673356 in flutter::Rasterizer::DrawToSurface(flutter::LayerTree&) rasterizer.cc:263
    #11 0x109675839 in flutter::Rasterizer::DoDraw(std::__1::unique_ptr<flutter::LayerTree, std::__1::default_delete<flutter::LayerTree> >) rasterizer.cc:166
    #12 0x10968201f in flutter::Rasterizer::Draw(fml::RefPtr<flutter::Pipeline<flutter::LayerTree> >)::$_0::operator()(std::__1::unique_ptr<flutter::LayerTree, std::__1::default_delete<flutter::LayerTree> >) const rasterizer.cc:119
    #13 0x109681e0f in decltype(std::__1::forward<flutter::Rasterizer::Draw(fml::RefPtr<flutter::Pipeline<flutter::LayerTree> >)::$_0&>(fp)(std::__1::forward<std::__1::unique_ptr<flutter::LayerTree, std::__1::default_delete<flutter::LayerTree> > >(fp0))) std::__1::__invoke<flutter::Rasterizer::Draw(fml::RefPtr<flutter::Pipeline<flutter::LayerTree> >)::$_0&, std::__1::unique_ptr<flutter::LayerTree, std::__1::default_delete<flutter::LayerTree> > >(flutter::Rasterizer::Draw(fml::RefPtr<flutter::Pipeline<flutter::LayerTree> >)::$_0&&&, std::__1::unique_ptr<flutter::LayerTree, std::__1::default_delete<flutter::LayerTree> >&&) type_traits:4350
    #14 0x109681c6f in void std::__1::__invoke_void_return_wrapper<void>::__call<flutter::Rasterizer::Draw(fml::RefPtr<flutter::Pipeline<flutter::LayerTree> >)::$_0&, std::__1::unique_ptr<flutter::LayerTree, std::__1::default_delete<flutter::LayerTree> > >(flutter::Rasterizer::Draw(fml::RefPtr<flutter::Pipeline<flutter::LayerTree> >)::$_0&&&, std::__1::unique_ptr<flutter::LayerTree, std::__1::default_delete<flutter::LayerTree> >&&) __functional_base:349
    #15 0x10967dc06 in std::__1::__function::__func<flutter::Rasterizer::Draw(fml::RefPtr<flutter::Pipeline<flutter::LayerTree> >)::$_0, std::__1::allocator<flutter::Rasterizer::Draw(fml::RefPtr<flutter::Pipeline<flutter::LayerTree> >)::$_0>, void (std::__1::unique_ptr<flutter::LayerTree, std::__1::default_delete<flutter::LayerTree> >)>::operator()(std::__1::unique_ptr<flutter::LayerTree, std::__1::default_delete<flutter::LayerTree> >&&) functional:1572
    #16 0x109682c11 in std::__1::function<void (std::__1::unique_ptr<flutter::LayerTree, std::__1::default_delete<flutter::LayerTree> >)>::operator()(std::__1::unique_ptr<flutter::LayerTree, std::__1::default_delete<flutter::LayerTree> >) const functional:1923
    #17 0x109674ada in flutter::Pipeline<flutter::LayerTree>::Consume(std::__1::function<void (std::__1::unique_ptr<flutter::LayerTree, std::__1::default_delete<flutter::LayerTree> >)>) pipeline.h:153
    #18 0x109673dac in flutter::Rasterizer::Draw(fml::RefPtr<flutter::Pipeline<flutter::LayerTree> >) rasterizer.cc:122
    #19 0x109792b0a in flutter::Shell::OnAnimatorDraw(fml::RefPtr<flutter::Pipeline<flutter::LayerTree> >)::$_28::operator()() const shell.cc:886
    #20 0x10979295a in decltype(std::__1::forward<flutter::Shell::OnAnimatorDraw(fml::RefPtr<flutter::Pipeline<flutter::LayerTree> >)::$_28&>(fp)()) std::__1::__invoke<flutter::Shell::OnAnimatorDraw(fml::RefPtr<flutter::Pipeline<flutter::LayerTree> >)::$_28&>(flutter::Shell::OnAnimatorDraw(fml::RefPtr<flutter::Pipeline<flutter::LayerTree> >)::$_28&&&) type_traits:4350
    #21 0x1097928aa in void std::__1::__invoke_void_return_wrapper<void>::__call<flutter::Shell::OnAnimatorDraw(fml::RefPtr<flutter::Pipeline<flutter::LayerTree> >)::$_28&>(flutter::Shell::OnAnimatorDraw(fml::RefPtr<flutter::Pipeline<flutter::LayerTree> >)::$_28&&&) __functional_base:349
    #22 0x10978edf1 in std::__1::__function::__func<flutter::Shell::OnAnimatorDraw(fml::RefPtr<flutter::Pipeline<flutter::LayerTree> >)::$_28, std::__1::allocator<flutter::Shell::OnAnimatorDraw(fml::RefPtr<flutter::Pipeline<flutter::LayerTree> >)::$_28>, void ()>::operator()() functional:1572
    #23 0x105e1303b in std::__1::function<void ()>::operator()() const functional:1923
    #24 0x107593f03 in fml::MessageLoopImpl::FlushTasks(fml::FlushType) message_loop_impl.cc:121
    #25 0x107593a17 in fml::MessageLoopImpl::RunExpiredTasksNow() message_loop_impl.cc:131
    #26 0x1075ded22 in fml::MessageLoopDarwin::OnTimerFire(__CFRunLoopTimer*, fml::MessageLoopDarwin*) message_loop_darwin.mm:75
    #27 0x7fff5095305f in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ (CoreFoundation:x86_64h+0x5a05f)
    #28 0x7fff50952c0b in __CFRunLoopDoTimer (CoreFoundation:x86_64h+0x59c0b)
    #29 0x7fff50952751 in __CFRunLoopDoTimers (CoreFoundation:x86_64h+0x59751)

```