summaryrefslogtreecommitdiff
path: root/source/html
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2016-10-05 19:24:34 +0100
committerRobin Watts <robin.watts@artifex.com>2016-10-06 11:48:16 +0100
commit61eff09d928439847274bf3152cd8f26c0218cf5 (patch)
treea88540eb67f351e043543ee092e408edd97fa84f /source/html
parent6aa13c725dcf461038b80c70a0e7a3ab0c7dd7d6 (diff)
downloadmupdf-61eff09d928439847274bf3152cd8f26c0218cf5.tar.xz
Bug 697182: Fix memory leak in html-layout.
Only create a text object if we are definitely going to use it, and then take care of exceptions being thrown.
Diffstat (limited to 'source/html')
-rw-r--r--source/html/html-layout.c39
1 files changed, 22 insertions, 17 deletions
diff --git a/source/html/html-layout.c b/source/html/html-layout.c
index 8b74caa0..19e58061 100644
--- a/source/html/html-layout.c
+++ b/source/html/html-layout.c
@@ -1721,8 +1721,6 @@ static void draw_list_mark(fz_context *ctx, fz_html *box, float page_top, float
fz_scale(&trm, box->em, -box->em);
- text = fz_new_text(ctx);
-
line = find_list_mark_anchor(ctx, box);
if (line)
{
@@ -1752,24 +1750,31 @@ static void draw_list_mark(fz_context *ctx, fz_html *box, float page_top, float
w += fz_advance_glyph(ctx, font, g, 0) * box->em;
}
- s = buf;
- trm.e = box->x - w;
- trm.f = y;
- while (*s)
- {
- s += fz_chartorune(&c, s);
- g = fz_encode_character_with_fallback(ctx, box->style.font, c, UCDN_SCRIPT_LATIN, FZ_LANG_UNSET, &font);
- fz_show_glyph(ctx, text, font, &trm, g, c, 0, 0, FZ_BIDI_NEUTRAL, FZ_LANG_UNSET);
- trm.e += fz_advance_glyph(ctx, font, g, 0) * box->em;
- }
+ text = fz_new_text(ctx);
- color[0] = box->style.color.r / 255.0f;
- color[1] = box->style.color.g / 255.0f;
- color[2] = box->style.color.b / 255.0f;
+ fz_try(ctx)
+ {
+ s = buf;
+ trm.e = box->x - w;
+ trm.f = y;
+ while (*s)
+ {
+ s += fz_chartorune(&c, s);
+ g = fz_encode_character_with_fallback(ctx, box->style.font, c, UCDN_SCRIPT_LATIN, FZ_LANG_UNSET, &font);
+ fz_show_glyph(ctx, text, font, &trm, g, c, 0, 0, FZ_BIDI_NEUTRAL, FZ_LANG_UNSET);
+ trm.e += fz_advance_glyph(ctx, font, g, 0) * box->em;
+ }
- fz_fill_text(ctx, dev, text, ctm, fz_device_rgb(ctx), color, 1);
+ color[0] = box->style.color.r / 255.0f;
+ color[1] = box->style.color.g / 255.0f;
+ color[2] = box->style.color.b / 255.0f;
- fz_drop_text(ctx, text);
+ fz_fill_text(ctx, dev, text, ctm, fz_device_rgb(ctx), color, 1);
+ }
+ fz_always(ctx)
+ fz_drop_text(ctx, text);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
}
static void draw_block_box(fz_context *ctx, fz_html *box, float page_top, float page_bot, fz_device *dev, const fz_matrix *ctm, hb_buffer_t *hb_buf)