From 2c81252f355e77c0bb49f79ea32bd64d7ebbde6b Mon Sep 17 00:00:00 2001
From: Sebastian Rasmussen <sebras@gmail.com>
Date: Mon, 12 Jun 2017 00:42:32 +0800
Subject: Drop HTML document in case of error.

---
 source/html/html-doc.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

(limited to 'source/html')

diff --git a/source/html/html-doc.c b/source/html/html-doc.c
index 67587fa1..566aeac6 100644
--- a/source/html/html-doc.c
+++ b/source/html/html-doc.c
@@ -187,16 +187,21 @@ htdoc_open_document(fz_context *ctx, const char *filename)
 	doc->super.lookup_metadata = htdoc_lookup_metadata;
 	doc->super.is_reflowable = 1;
 
-	doc->zip = fz_open_directory(ctx, dirname);
-	doc->set = fz_new_html_font_set(ctx);
-
-	buf = fz_read_file(ctx, filename);
 	fz_try(ctx)
+	{
+		doc->zip = fz_open_directory(ctx, dirname);
+		doc->set = fz_new_html_font_set(ctx);
+
+		buf = fz_read_file(ctx, filename);
 		doc->html = 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_drop_document(ctx, &doc->super);
 		fz_rethrow(ctx);
+	}
 
 	return (fz_document*)doc;
 }
-- 
cgit v1.2.3