From cdd7db2674e1f3edb603337d370fd9e57cd2d74a Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Mon, 31 Oct 2016 11:16:04 -0700 Subject: [PATCH] Fix a leak of RenderObjects in Paragraph/ParagraphBuilder (#3189) The RenderView destructor does not delete its descendants. RenderObject::destroy must be called to delete the object tree along with other cleanup tasks. Also associate a CustomFontData with dynamically loaded fonts in order to get the desired FontDataCache behavior at RenderObject::destroy time. --- lib/ui/text/paragraph.cc | 8 +++++--- lib/ui/text/paragraph_builder.cc | 8 +++++--- runtime/asset_font_selector.cc | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/ui/text/paragraph.cc b/lib/ui/text/paragraph.cc index 6b7dc3a1460..c7fc683385b 100644 --- a/lib/ui/text/paragraph.cc +++ b/lib/ui/text/paragraph.cc @@ -42,9 +42,11 @@ Paragraph::Paragraph(PassOwnPtr renderView) : m_renderView(renderView) {} Paragraph::~Paragraph() { - PassOwnPtr renderView = m_renderView.release(); - Threads::UI()->PostTask( - [renderView]() { /* renderView's destructor runs. */ }); + if (m_renderView) { + RenderView* renderView = m_renderView.leakPtr(); + Threads::UI()->PostTask( + [renderView]() { renderView->destroy(); }); + } } double Paragraph::width() { diff --git a/lib/ui/text/paragraph_builder.cc b/lib/ui/text/paragraph_builder.cc index fde8d59a5b9..6745698c755 100644 --- a/lib/ui/text/paragraph_builder.cc +++ b/lib/ui/text/paragraph_builder.cc @@ -208,9 +208,11 @@ ParagraphBuilder::ParagraphBuilder(tonic::Int32List& encoded, } ParagraphBuilder::~ParagraphBuilder() { - PassOwnPtr renderView = m_renderView.release(); - Threads::UI()->PostTask( - [renderView]() { /* renderView's destructor runs. */ }); + if (m_renderView) { + RenderView* renderView = m_renderView.leakPtr(); + Threads::UI()->PostTask( + [renderView]() { renderView->destroy(); }); + } } void ParagraphBuilder::pushStyle(tonic::Int32List& encoded, diff --git a/runtime/asset_font_selector.cc b/runtime/asset_font_selector.cc index 82ca7e8a7c7..1c727dbc53c 100644 --- a/runtime/asset_font_selector.cc +++ b/runtime/asset_font_selector.cc @@ -186,7 +186,7 @@ PassRefPtr AssetFontSelector::getFontData( font_description.orientation(), font_description.useSubpixelPositioning()); - font_data = SimpleFontData::create(platform_data); + font_data = SimpleFontData::create(platform_data, CustomFontData::create()); font_platform_data_cache_.set(key, font_data); }