summaryrefslogtreecommitdiff
path: root/source/html
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-01-07 13:37:48 +0100
committerTor Andersson <tor.andersson@artifex.com>2016-01-08 13:00:45 +0100
commit63c8290faf4cec2c25a7ae4addde38ad2e5817f9 (patch)
treed1928c0bef84206e6d1db41a0e09b8d20d37315f /source/html
parenta57d4a1eb389fe63fb92207e574f1e1691cf5e4c (diff)
downloadmupdf-63c8290faf4cec2c25a7ae4addde38ad2e5817f9.tar.xz
epub: Fix memory leaks.
Diffstat (limited to 'source/html')
-rw-r--r--source/html/epub-doc.c3
-rw-r--r--source/html/html-doc.c3
-rw-r--r--source/html/html-layout.c14
3 files changed, 14 insertions, 6 deletions
diff --git a/source/html/epub-doc.c b/source/html/epub-doc.c
index 34285642..2f09fe50 100644
--- a/source/html/epub-doc.c
+++ b/source/html/epub-doc.c
@@ -179,6 +179,7 @@ epub_close_document(fz_context *ctx, fz_document *doc_)
}
fz_drop_archive(ctx, doc->zip);
fz_drop_html_font_set(ctx, doc->set);
+ fz_drop_outline(ctx, doc->outline);
fz_free(ctx, doc->dc_title);
fz_free(ctx, doc->dc_creator);
fz_free(ctx, doc);
@@ -423,7 +424,7 @@ epub_init(fz_context *ctx, fz_archive *zip)
{
epub_document *doc;
- doc = fz_malloc_struct(ctx, epub_document);
+ doc = fz_new_document(ctx, sizeof *doc);
doc->zip = zip;
doc->set = fz_new_html_font_set(ctx);
diff --git a/source/html/html-doc.c b/source/html/html-doc.c
index 101a4c42..6ad5c3e8 100644
--- a/source/html/html-doc.c
+++ b/source/html/html-doc.c
@@ -117,7 +117,8 @@ htdoc_open_document_with_stream(fz_context *ctx, fz_stream *file)
html_document *doc;
fz_buffer *buf;
- doc = fz_malloc_struct(ctx, html_document);
+ doc = fz_new_document(ctx, sizeof *doc);
+
doc->super.close = htdoc_close_document;
doc->super.layout = htdoc_layout;
doc->super.count_pages = htdoc_count_pages;
diff --git a/source/html/html-layout.c b/source/html/html-layout.c
index b22dd106..f9c34bc3 100644
--- a/source/html/html-layout.c
+++ b/source/html/html-layout.c
@@ -217,8 +217,8 @@ static void generate_text(fz_context *ctx, fz_pool *pool, fz_html *box, const ch
static void generate_image(fz_context *ctx, fz_pool *pool, fz_archive *zip, const char *base_uri, fz_html *box, const char *src)
{
- fz_image *img;
- fz_buffer *buf;
+ fz_image *img = NULL;
+ fz_buffer *buf = NULL;
char path[2048];
fz_html *flow = box;
@@ -231,14 +231,20 @@ static void generate_image(fz_context *ctx, fz_pool *pool, fz_archive *zip, cons
fz_urldecode(path);
fz_cleanname(path);
+ fz_var(buf);
+ fz_var(img);
+
fz_try(ctx)
{
buf = fz_read_archive_entry(ctx, zip, path);
img = fz_new_image_from_buffer(ctx, buf);
- fz_drop_buffer(ctx, buf);
-
add_flow_image(ctx, pool, flow, &box->style, img);
}
+ fz_always(ctx)
+ {
+ fz_drop_buffer(ctx, buf);
+ fz_drop_image(ctx, img);
+ }
fz_catch(ctx)
{
const char *alt = "[image]";