diff options
author | Sebastian Rasmussen <sebras@gmail.com> | 2017-06-12 19:54:56 +0800 |
---|---|---|
committer | Sebastian Rasmussen <sebras@gmail.com> | 2017-06-16 23:47:48 +0800 |
commit | 586bec69f15ec52e062dca38942534f828fb9dd3 (patch) | |
tree | 5e55451866370246ab7cb40fdf1bb6a03a240892 /source/html | |
parent | f7a0321c03fde85aab74a09b5770277915a7f274 (diff) | |
download | mupdf-586bec69f15ec52e062dca38942534f828fb9dd3.tar.xz |
epub: Free chapter, path and buffer in case of error.
Diffstat (limited to 'source/html')
-rw-r--r-- | source/html/epub-doc.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/source/html/epub-doc.c b/source/html/epub-doc.c index 20b5c2ef..0adab461 100644 --- a/source/html/epub-doc.c +++ b/source/html/epub-doc.c @@ -286,20 +286,34 @@ static epub_chapter * epub_parse_chapter(fz_context *ctx, epub_document *doc, const char *path) { fz_archive *zip = doc->zip; - fz_buffer *buf; + fz_buffer *buf = NULL; epub_chapter *ch; char base_uri[2048]; fz_dirname(base_uri, path, sizeof base_uri); - buf = fz_read_archive_entry(ctx, zip, path); - ch = fz_malloc_struct(ctx, epub_chapter); - ch->path = fz_strdup(ctx, path); - ch->html = fz_parse_html(ctx, doc->set, zip, base_uri, buf, fz_user_css(ctx)); + ch->path = NULL; + ch->html = NULL; ch->next = NULL; - fz_drop_buffer(ctx, buf); + fz_var(buf); + + fz_try(ctx) + { + buf = fz_read_archive_entry(ctx, zip, path); + ch->path = fz_strdup(ctx, path); + ch->html = fz_parse_html(ctx, doc->set, zip, base_uri, buf, fz_user_css(ctx)); + } + fz_always(ctx) + fz_drop_buffer(ctx, buf); + fz_catch(ctx) + { + fz_drop_html(ctx, ch->html); + fz_free(ctx, ch->path); + fz_free(ctx, ch); + fz_rethrow(ctx); + } return ch; } |