diff options
author | Sebastian Rasmussen <sebras@gmail.com> | 2016-12-01 17:16:23 -0500 |
---|---|---|
committer | Sebastian Rasmussen <sebras@gmail.com> | 2016-12-14 16:31:13 +0100 |
commit | f2e8dfeb3d4ccdcdbdf8e2e122883b0ec7145bc6 (patch) | |
tree | ec26f1ac1723b4d91adbe89b35383f8475dd9767 /source | |
parent | 2590fed7a355a421f062ebd4293df892800fa7ac (diff) | |
download | mupdf-f2e8dfeb3d4ccdcdbdf8e2e122883b0ec7145bc6.tar.xz |
Fix document leak when mutool info throws.
Diffstat (limited to 'source')
-rw-r--r-- | source/tools/pdfinfo.c | 58 |
1 files changed, 32 insertions, 26 deletions
diff --git a/source/tools/pdfinfo.c b/source/tools/pdfinfo.c index edec4217..e9821824 100644 --- a/source/tools/pdfinfo.c +++ b/source/tools/pdfinfo.c @@ -954,41 +954,47 @@ pdfinfo_info(fz_context *ctx, fz_output *out, char *filename, char *password, in glo.ctx = ctx; state = NO_FILE_OPENED; - while (argidx < argc) + + fz_try(ctx) { - if (state == NO_FILE_OPENED || !fz_is_page_range(ctx, argv[argidx])) + while (argidx < argc) { - if (state == NO_INFO_GATHERED) + if (state == NO_FILE_OPENED || !fz_is_page_range(ctx, argv[argidx])) { - showinfo(ctx, &glo, filename, show, "1-N"); - } + if (state == NO_INFO_GATHERED) + { + showinfo(ctx, &glo, filename, show, "1-N"); + } - closexref(ctx, &glo); + closexref(ctx, &glo); - filename = argv[argidx]; - fz_printf(ctx, out, "%s:\n", filename); - glo.doc = pdf_open_document(glo.ctx, filename); - if (pdf_needs_password(ctx, glo.doc)) - if (!pdf_authenticate_password(ctx, glo.doc, password)) - fz_throw(glo.ctx, FZ_ERROR_GENERIC, "cannot authenticate password: %s", filename); - glo.pagecount = pdf_count_pages(ctx, glo.doc); + filename = argv[argidx]; + fz_printf(ctx, out, "%s:\n", filename); + glo.doc = pdf_open_document(glo.ctx, filename); + if (pdf_needs_password(ctx, glo.doc)) + if (!pdf_authenticate_password(ctx, glo.doc, password)) + fz_throw(glo.ctx, FZ_ERROR_GENERIC, "cannot authenticate password: %s", filename); + glo.pagecount = pdf_count_pages(ctx, glo.doc); - showglobalinfo(ctx, &glo); - state = NO_INFO_GATHERED; - } - else - { - showinfo(ctx, &glo, filename, show, argv[argidx]); - state = INFO_SHOWN; + showglobalinfo(ctx, &glo); + state = NO_INFO_GATHERED; + } + else + { + showinfo(ctx, &glo, filename, show, argv[argidx]); + state = INFO_SHOWN; + } + + argidx++; } - argidx++; + if (state == NO_INFO_GATHERED) + showinfo(ctx, &glo, filename, show, "1-N"); } - - if (state == NO_INFO_GATHERED) - showinfo(ctx, &glo, filename, show, "1-N"); - - closexref(ctx, &glo); + fz_always(ctx) + closexref(ctx, &glo); + fz_catch(ctx) + fz_rethrow(ctx); } int pdfinfo_main(int argc, char **argv) |