summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2012-08-04 19:31:53 +0200
committerSebastian Rasmussen <sebras@gmail.com>2012-08-06 13:59:02 +0200
commit4c00e74b4124474a736678e5554f9d8057c78de8 (patch)
tree9b48569ee2d1960dc7ab2a67f14173dbdfbd3d66
parent966ae9dc4ca3edce4ff592028baeb69fcebddeb7 (diff)
downloadmupdf-4c00e74b4124474a736678e5554f9d8057c78de8.tar.xz
Handle exceptions better in mupdfclean
pdf_write_document() may throw an exception and this was uncaught up until now.
-rw-r--r--apps/mupdfclean.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/apps/mupdfclean.c b/apps/mupdfclean.c
index 6b185668..fdf9b412 100644
--- a/apps/mupdfclean.c
+++ b/apps/mupdfclean.c
@@ -161,6 +161,7 @@ int pdfclean_main(int argc, char **argv)
int c;
int subset;
fz_write_options opts;
+ int write_failed = 0;
opts.do_garbage = 0;
opts.do_expand = 0;
@@ -204,18 +205,29 @@ int pdfclean_main(int argc, char **argv)
exit(1);
}
- xref = pdf_open_document_no_run(ctx, infile);
- if (pdf_needs_password(xref))
- if (!pdf_authenticate_password(xref, password))
- fz_throw(ctx, "cannot authenticate password: %s", infile);
+ fz_try(ctx)
+ {
+ xref = pdf_open_document_no_run(ctx, infile);
+ if (pdf_needs_password(xref))
+ if (!pdf_authenticate_password(xref, password))
+ fz_throw(ctx, "cannot authenticate password: %s", infile);
- /* Only retain the specified subset of the pages */
- if (subset)
- retainpages(argc, argv);
+ /* Only retain the specified subset of the pages */
+ if (subset)
+ retainpages(argc, argv);
- pdf_write_document(xref, outfile, &opts);
+ pdf_write_document(xref, outfile, &opts);
+ }
+ fz_always(ctx)
+ {
+ pdf_close_document(xref);
+ }
+ fz_catch(ctx)
+ {
+ write_failed = 1;
+ }
- pdf_close_document(xref);
fz_free_context(ctx);
- return 0;
+
+ return write_failed ? 1 : 0;
}