diff --git a/zathura/database-plain.c b/zathura/database-plain.c index 22e4636..388a7b3 100644 --- a/zathura/database-plain.c +++ b/zathura/database-plain.c @@ -246,10 +246,7 @@ error_free: g_free(priv->bookmark_path); priv->bookmark_path = NULL; - if (priv->bookmark_monitor != NULL) { - g_object_unref(priv->bookmark_monitor); - priv->bookmark_monitor = NULL; - } + g_clear_object(&priv->bookmark_monitor); if (priv->bookmarks != NULL) { g_key_file_free(priv->bookmarks); @@ -260,10 +257,7 @@ error_free: g_free(priv->history_path); priv->history_path = NULL; - if (priv->history_monitor != NULL) { - g_object_unref(priv->history_monitor); - priv->history_monitor = NULL; - } + g_clear_object(&priv->history_monitor); if (priv->history != NULL) { g_key_file_free(priv->history); diff --git a/zathura/document.c b/zathura/document.c index d094e2e..70f06e5 100644 --- a/zathura/document.c +++ b/zathura/document.c @@ -119,8 +119,7 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* uri, document->uri = g_strdup(uri); if (document->uri == NULL) { document->basename = g_file_get_basename(file); - } - else { + } else { GFile *gf = g_file_new_for_uri(document->uri); document->basename = g_file_get_basename(gf); g_object_unref(gf); diff --git a/zathura/print.c b/zathura/print.c index a31df9e..df6087b 100644 --- a/zathura/print.c +++ b/zathura/print.c @@ -215,12 +215,8 @@ cb_print_done(GtkPrintOperation* operation, GtkPrintOperationResult result, zathura_t* zathura) { if (result == GTK_PRINT_OPERATION_RESULT_APPLY) { - if (zathura->print.settings != NULL) { - g_object_unref(zathura->print.settings); - } - if (zathura->print.page_setup != NULL) { - g_object_unref(zathura->print.page_setup); - } + g_clear_object(&zathura->print.settings); + g_clear_object(&zathura->print.page_setup); /* save previous settings */ zathura->print.settings = g_object_ref(gtk_print_operation_get_print_settings(operation)); diff --git a/zathura/zathura.c b/zathura/zathura.c index 2979324..5d96de2 100644 --- a/zathura/zathura.c +++ b/zathura/zathura.c @@ -391,10 +391,7 @@ zathura_free(zathura_t* zathura) #endif /* stop D-Bus */ - if (zathura->dbus != NULL) { - g_object_unref(zathura->dbus); - zathura->dbus = NULL; - } + g_clear_object(&zathura->dbus); if (zathura->ui.session != NULL) { girara_session_destroy(zathura->ui.session); @@ -415,18 +412,11 @@ zathura_free(zathura_t* zathura) girara_list_free(zathura->bookmarks.bookmarks); /* database */ - if (zathura->database != NULL) { - g_object_unref(G_OBJECT(zathura->database)); - } + g_clear_object(&zathura->database); /* free print settings */ - if (zathura->print.settings != NULL) { - g_object_unref(zathura->print.settings); - } - - if (zathura->print.page_setup != NULL) { - g_object_unref(zathura->print.page_setup); - } + g_clear_object(&zathura->print.settings); + g_clear_object(&zathura->print.page_setup); /* free registered plugins */ zathura_plugin_manager_free(zathura->plugins.manager); @@ -1216,10 +1206,7 @@ document_close(zathura_t* zathura, bool keep_monitor) /* remove monitor */ if (keep_monitor == false) { - if (zathura->file_monitor.monitor != NULL) { - g_object_unref(zathura->file_monitor.monitor); - zathura->file_monitor.monitor = NULL; - } + g_clear_object(&zathura->file_monitor.monitor); if (zathura->file_monitor.password != NULL) { g_free(zathura->file_monitor.password); @@ -1245,8 +1232,7 @@ document_close(zathura_t* zathura, bool keep_monitor) zathura->jumplist.size = 0; /* release render thread */ - g_object_unref(zathura->sync.render_thread); - zathura->sync.render_thread = NULL; + g_clear_object(&zathura->sync.render_thread); /* remove widgets */ gtk_container_foreach(GTK_CONTAINER(zathura->ui.page_widget), remove_page_from_table, NULL);