From ecc5c28eb0eb9801bf7c434c1483d6e3ab997075 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Mon, 26 Sep 2016 02:31:32 +0800 Subject: Fix memory leak when opening html/loading raw stream. --- source/html/html-doc.c | 13 ++++++++++--- source/pdf/pdf-stream.c | 8 ++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/source/html/html-doc.c b/source/html/html-doc.c index f14ddc35..733dd620 100644 --- a/source/html/html-doc.c +++ b/source/html/html-doc.c @@ -129,9 +129,16 @@ htdoc_open_document_with_stream(fz_context *ctx, fz_stream *file) doc->set = fz_new_html_font_set(ctx); buf = fz_read_all(ctx, file, 0); - fz_write_buffer_byte(ctx, buf, 0); - doc->box = fz_parse_html(ctx, doc->set, doc->zip, ".", buf, fz_user_css(ctx)); - fz_drop_buffer(ctx, buf); + + fz_try(ctx) + { + fz_write_buffer_byte(ctx, buf, 0); + doc->box = fz_parse_html(ctx, doc->set, doc->zip, ".", buf, fz_user_css(ctx)); + } + fz_always(ctx) + fz_drop_buffer(ctx, buf); + fz_catch(ctx) + fz_rethrow(ctx); return (fz_document*)doc; } diff --git a/source/pdf/pdf-stream.c b/source/pdf/pdf-stream.c index 9ff136b2..39f85b0b 100644 --- a/source/pdf/pdf-stream.c +++ b/source/pdf/pdf-stream.c @@ -458,9 +458,13 @@ pdf_load_raw_stream_number(fz_context *ctx, pdf_document *doc, int num) stm = pdf_open_raw_stream_number(ctx, doc, num); - buf = fz_read_all(ctx, stm, len); + fz_try(ctx) + buf = fz_read_all(ctx, stm, len); + fz_always(ctx) + fz_drop_stream(ctx, stm); + fz_catch(ctx) + fz_rethrow(ctx); - fz_drop_stream(ctx, stm); return buf; } -- cgit v1.2.3