From 48fbce9f2b0701d54a60fde6009594d95f299656 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Wed, 22 May 2013 14:20:15 -0400 Subject: [PATCH] Avoid creating a TextRun which won't be used, thus creating a permanent cycle with no way to break it. --- src/components/servo/layout/inline.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/servo/layout/inline.rs b/src/components/servo/layout/inline.rs index 2798361131a..b1b2c495029 100644 --- a/src/components/servo/layout/inline.rs +++ b/src/components/servo/layout/inline.rs @@ -316,11 +316,18 @@ impl TextRunScanner { // and then letting `FontGroup` decide which `Font` to stick into the text run. let font_style = in_boxes[self.clump.begin()].font_style(); let fontgroup = ctx.font_ctx.get_resolved_font_for_style(&font_style); - let run = @TextRun::new(fontgroup.fonts[0], run_str); + + // TextRuns contain a cycle which is usually resolved by the teardown + // sequence. If no clump takes ownership, however, it will leak. + let clump = self.clump; + let run = if clump.length() != 0 { + Some(@TextRun::new(fontgroup.fonts[0], run_str)) + } else { + None + }; // Make new boxes with the run and adjusted text indices. debug!("TextRunScanner: pushing box(es) in range: %?", self.clump); - let clump = self.clump; for clump.eachi |i| { let range = new_ranges[i - self.clump.begin()]; if range.length() == 0 { @@ -331,7 +338,7 @@ impl TextRunScanner { } do in_boxes[i].with_imm_base |base| { - let new_box = @mut adapt_textbox_with_range(*base, run, range); + let new_box = @mut adapt_textbox_with_range(*base, run.get(), range); out_boxes.push(TextRenderBoxClass(new_box)); } }