summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2016-09-26 02:31:32 +0800
committerSebastian Rasmussen <sebras@gmail.com>2016-09-26 18:35:33 +0800
commitecc5c28eb0eb9801bf7c434c1483d6e3ab997075 (patch)
treeb2a29f01589cf12d247101f443a48355a1e44461
parentdf6fca4d8306c06e262ae8ed88c90d7b0400dac5 (diff)
downloadmupdf-ecc5c28eb0eb9801bf7c434c1483d6e3ab997075.tar.xz
Fix memory leak when opening html/loading raw stream.
-rw-r--r--source/html/html-doc.c13
-rw-r--r--source/pdf/pdf-stream.c8
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;
}