From 2791ae43f075768c65deb9b5c6a37abfebf86d16 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sat, 28 Apr 2012 18:42:54 +0200 Subject: Free document/app when document cannot be shown in X11 viewer. --- apps/x11_main.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'apps/x11_main.c') diff --git a/apps/x11_main.c b/apps/x11_main.c index 6ab5b43a..941afcfa 100644 --- a/apps/x11_main.c +++ b/apps/x11_main.c @@ -59,6 +59,7 @@ extern void ximage_blit(Drawable d, GC gc, int dstx, int dsty, int srcx, int srcy, int srcw, int srch, int srcstride); void windrawstringxor(pdfapp_t *app, int x, int y, char *s); +void cleanup(pdfapp_t *app); static Display *xdpy; static Atom XA_TARGETS; @@ -100,6 +101,7 @@ static int showingpage = 0; void winerror(pdfapp_t *app, char *msg) { fprintf(stderr, "mupdf: error: %s\n", msg); + cleanup(app); exit(1); } @@ -215,6 +217,27 @@ void winclose(pdfapp_t *app) closing = 1; } +void cleanup(pdfapp_t *app) +{ + fz_context *ctx = app->ctx; + + pdfapp_close(app); + + XDestroyWindow(xdpy, xwin); + + XFreePixmap(xdpy, xicon); + + XFreeCursor(xdpy, xcwait); + XFreeCursor(xdpy, xchand); + XFreeCursor(xdpy, xcarrow); + + XFreeGC(xdpy, xgc); + + XCloseDisplay(xdpy); + + fz_free_context(ctx); +} + static int winresolution() { return DisplayWidth(xdpy, xscr) * 25.4 / @@ -825,21 +848,7 @@ int main(int argc, char **argv) } } - pdfapp_close(&gapp); - - XDestroyWindow(xdpy, xwin); - - XFreePixmap(xdpy, xicon); - - XFreeCursor(xdpy, xcwait); - XFreeCursor(xdpy, xchand); - XFreeCursor(xdpy, xcarrow); - - XFreeGC(xdpy, xgc); - - XCloseDisplay(xdpy); - - fz_free_context(ctx); + cleanup(&gapp); return 0; } -- cgit v1.2.3