diff --git a/callbacks.c b/callbacks.c index 8bd8ba1..5bda659 100644 --- a/callbacks.c +++ b/callbacks.c @@ -18,8 +18,13 @@ #include "page_widget.h" gboolean -cb_destroy(GtkWidget* UNUSED(widget), gpointer UNUSED(data)) +cb_destroy(GtkWidget* UNUSED(widget), zathura_t* zathura) { + if (zathura != NULL && zathura->document != NULL) { + zathura_document_free(zathura->document); + zathura->document = NULL; + } + gtk_main_quit(); return TRUE; } diff --git a/callbacks.h b/callbacks.h index 19630d1..f575bca 100644 --- a/callbacks.h +++ b/callbacks.h @@ -8,15 +8,16 @@ #include #include "document.h" +#include "zathura.h" /** * Quits the current zathura session * * @param widget The gtk window of zathura - * @param data NULL + * @param zathura Correspondending zathura session * @return true if no error occured and the event has been handled */ -gboolean cb_destroy(GtkWidget* widget, gpointer data); +gboolean cb_destroy(GtkWidget* widget, zathura_t* zathura); /** * This function gets called when the buffer of girara changes diff --git a/zathura.c b/zathura.c index d0829b1..7812b18 100644 --- a/zathura.c +++ b/zathura.c @@ -225,7 +225,7 @@ zathura_init(int argc, char* argv[]) girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.file, "[No Name]"); /* signals */ - g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), NULL); + g_signal_connect(G_OBJECT(zathura->ui.session->gtk.window), "destroy", G_CALLBACK(cb_destroy), zathura); /* save page padding */ zathura->global.page_padding = 1;