diff options
author | Robin Watts <robin.watts@artifex.com> | 2011-12-08 16:26:31 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2011-12-08 16:26:31 +0000 |
commit | e64a57b1e9c2ba6c6f54eff73c414be9e78dafbe (patch) | |
tree | 92111e795da1f8aa002285cda531a2346a9b588e /apps | |
parent | 0e6931ad400fbf2780bd06530a3135653f8c9b4f (diff) | |
download | mupdf-e64a57b1e9c2ba6c6f54eff73c414be9e78dafbe.tar.xz |
Fix exception handling in pdfdraw to avoid leaks.
Remove use of 'die', in place of proper exception handling.
Diffstat (limited to 'apps')
-rw-r--r-- | apps/pdfdraw.c | 86 |
1 files changed, 45 insertions, 41 deletions
diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c index c1d2a779..6d43dc01 100644 --- a/apps/pdfdraw.c +++ b/apps/pdfdraw.c @@ -36,12 +36,6 @@ struct { int minpage, maxpage; } timing; -static void die(fz_error error) -{ - fz_error_handle(error, "aborting"); - exit(1); -} - static void usage(void) { fprintf(stderr, @@ -111,7 +105,7 @@ static void drawpage(pdf_xref *xref, int pagenum) } fz_catch(ctx) { - die(fz_error_note(1, "cannot load page %d in file '%s'", pagenum, filename)); + fz_throw(ctx, "cannot load page %d in file '%s'", pagenum, filename); } list = NULL; @@ -126,7 +120,8 @@ static void drawpage(pdf_xref *xref, int pagenum) } fz_catch(ctx) { - die(fz_error_note(1, "cannot draw page %d in file '%s'", pagenum, filename)); + fz_free_device(dev); + fz_throw(ctx, "cannot draw page %d in file '%s'", pagenum, filename); } fz_free_device(dev); } @@ -325,11 +320,12 @@ int main(int argc, char **argv) char *password = ""; int grayscale = 0; int accelerate = 1; - pdf_xref *xref; - fz_error error; + pdf_xref *xref = NULL; int c; fz_context *ctx; + fz_var(xref); + while ((c = fz_getopt(argc, argv, "lo:p:r:R:Aab:dgmtx5G:I")) != -1) { switch (c) @@ -397,45 +393,53 @@ int main(int argc, char **argv) if (showxml) printf("<?xml version=\"1.0\"?>\n"); - while (fz_optind < argc) + fz_try(ctx) { - filename = argv[fz_optind++]; - - fz_try(ctx) + while (fz_optind < argc) { - xref = pdf_open_xref(ctx, filename, password); - } - fz_catch(ctx) - { - die(fz_error_note(error, "cannot open document: %s", filename)); - } + filename = argv[fz_optind++]; - fz_try(ctx) - { - pdf_load_page_tree(xref); - } - fz_catch(ctx) - { - die(fz_error_note(error, "cannot load page tree: %s", filename)); - } + fz_try(ctx) + { + xref = pdf_open_xref(ctx, filename, password); + } + fz_catch(ctx) + { + fz_throw(ctx, "cannot open document: %s", filename); + } - if (showxml) - printf("<document name=\"%s\">\n", filename); + fz_try(ctx) + { + pdf_load_page_tree(xref); + } + fz_catch(ctx) + { + fz_throw(ctx, "cannot load page tree: %s", filename); + } - if (showoutline) - drawoutline(xref); + if (showxml) + printf("<document name=\"%s\">\n", filename); - if (showtext || showxml || showtime || showmd5 || output) - { - if (fz_optind == argc || !isrange(argv[fz_optind])) - drawrange(xref, "1-"); - if (fz_optind < argc && isrange(argv[fz_optind])) - drawrange(xref, argv[fz_optind++]); - } + if (showoutline) + drawoutline(xref); + + if (showtext || showxml || showtime || showmd5 || output) + { + if (fz_optind == argc || !isrange(argv[fz_optind])) + drawrange(xref, "1-"); + if (fz_optind < argc && isrange(argv[fz_optind])) + drawrange(xref, argv[fz_optind++]); + } - if (showxml) - printf("</document>\n"); + if (showxml) + printf("</document>\n"); + pdf_free_xref(xref); + xref = NULL; + } + } + fz_catch(ctx) + { pdf_free_xref(xref); } |