diff --git a/libdocument/ev-annotation.c b/libdocument/ev-annotation.c index 1613fb2a..68cd3193 100644 --- a/libdocument/ev-annotation.c +++ b/libdocument/ev-annotation.c @@ -145,25 +145,10 @@ ev_annotation_finalize (GObject *object) { EvAnnotation *annot = EV_ANNOTATION (object); - if (annot->page) { - g_object_unref (annot->page); - annot->page = NULL; - } - - if (annot->contents) { - g_free (annot->contents); - annot->contents = NULL; - } - - if (annot->name) { - g_free (annot->name); - annot->name = NULL; - } - - if (annot->modified) { - g_free (annot->modified); - annot->modified = NULL; - } + g_clear_object (&annot->page); + g_clear_pointer (&annot->contents, g_free); + g_clear_pointer (&annot->name, g_free); + g_clear_pointer (&annot->modified, g_free); G_OBJECT_CLASS (ev_annotation_parent_class)->finalize (object); } @@ -1279,10 +1264,7 @@ ev_annotation_attachment_finalize (GObject *object) { EvAnnotationAttachment *annot = EV_ANNOTATION_ATTACHMENT (object); - if (annot->attachment) { - g_object_unref (annot->attachment); - annot->attachment = NULL; - } + g_clear_object (&annot->attachment); G_OBJECT_CLASS (ev_annotation_attachment_parent_class)->finalize (object); } diff --git a/libdocument/ev-attachment.c b/libdocument/ev-attachment.c index 5959f5a7..82c759b0 100644 --- a/libdocument/ev-attachment.c +++ b/libdocument/ev-attachment.c @@ -70,35 +70,15 @@ ev_attachment_finalize (GObject *object) EvAttachment *attachment = EV_ATTACHMENT (object); EvAttachmentPrivate *priv = GET_PRIVATE (attachment); - if (priv->name) { - g_free (priv->name); - priv->name = NULL; - } - - if (priv->description) { - g_free (priv->description); - priv->description = NULL; - } - - if (priv->data) { - g_free (priv->data); - priv->data = NULL; - } - - if (priv->mime_type) { - g_free (priv->mime_type); - priv->mime_type = NULL; - } - - if (priv->app) { - g_object_unref (priv->app); - priv->app = NULL; - } + g_clear_pointer (&priv->name, g_free); + g_clear_pointer (&priv->description, g_free); + g_clear_pointer (&priv->data, g_free); + g_clear_pointer (&priv->mime_type, g_free); + g_clear_object (&priv->app); if (priv->tmp_file) { ev_tmp_file_unlink (priv->tmp_file); - g_object_unref (priv->tmp_file); - priv->tmp_file = NULL; + g_clear_object (&priv->tmp_file); } G_OBJECT_CLASS (ev_attachment_parent_class)->finalize (object); diff --git a/libdocument/ev-debug.c b/libdocument/ev-debug.c index 9220c0ce..561e8cfc 100644 --- a/libdocument/ev-debug.c +++ b/libdocument/ev-debug.c @@ -100,10 +100,7 @@ _ev_debug_init (void) void _ev_debug_shutdown (void) { - if (timers) { - g_hash_table_destroy (timers); - timers = NULL; - } + g_clear_pointer (&timers, g_hash_table_destroy); } void diff --git a/libdocument/ev-document-factory.c b/libdocument/ev-document-factory.c index e3f13424..4b36be50 100644 --- a/libdocument/ev-document-factory.c +++ b/libdocument/ev-document-factory.c @@ -265,17 +265,10 @@ _ev_document_factory_init (void) void _ev_document_factory_shutdown (void) { - g_list_foreach (ev_backends_list, (GFunc) _ev_backend_info_unref, NULL); - g_list_free (ev_backends_list); - ev_backends_list = NULL; + g_list_free_full (g_steal_pointer (&ev_backends_list), (GDestroyNotify) _ev_backend_info_unref); - if (ev_module_hash != NULL) { - g_hash_table_unref (ev_module_hash); - ev_module_hash = NULL; - } - - g_free (ev_backends_dir); - ev_backends_dir = NULL; + g_clear_pointer (&ev_module_hash, g_hash_table_unref); + g_clear_pointer (&ev_backends_dir, g_free); } /** @@ -336,8 +329,7 @@ ev_document_factory_get_document_full (const char *uri, return document; } - g_object_unref (document); - document = NULL; + g_clear_object (&document); } /* Try again with slow mime detection */ @@ -381,9 +373,7 @@ ev_document_factory_get_document_full (const char *uri, return document; } - g_object_unref (document); - document = NULL; - + g_clear_object (&document); g_propagate_error (error, err); } diff --git a/libdocument/ev-document.c b/libdocument/ev-document.c index e9af17a1..0e32c66b 100644 --- a/libdocument/ev-document.c +++ b/libdocument/ev-document.c @@ -113,27 +113,11 @@ ev_document_finalize (GObject *object) { EvDocument *document = EV_DOCUMENT (object); - if (document->priv->uri) { - g_free (document->priv->uri); - document->priv->uri = NULL; - } - - if (document->priv->page_sizes) { - g_free (document->priv->page_sizes); - document->priv->page_sizes = NULL; - } - + g_clear_pointer (&document->priv->uri, g_free); + g_clear_pointer (&document->priv->page_sizes, g_free); g_clear_pointer (&document->priv->page_labels, g_strfreev); - - if (document->priv->info) { - ev_document_info_free (document->priv->info); - document->priv->info = NULL; - } - - if (document->priv->synctex_scanner) { - synctex_scanner_free (document->priv->synctex_scanner); - document->priv->synctex_scanner = NULL; - } + g_clear_pointer (&document->priv->info, ev_document_info_free); + g_clear_pointer (&document->priv->synctex_scanner, synctex_scanner_free); G_OBJECT_CLASS (ev_document_parent_class)->finalize (object); } diff --git a/libdocument/ev-file-helpers.c b/libdocument/ev-file-helpers.c index e4f7408e..75656b04 100644 --- a/libdocument/ev-file-helpers.c +++ b/libdocument/ev-file-helpers.c @@ -121,8 +121,7 @@ _ev_file_helpers_shutdown (void) if (tmp_dir != NULL) g_rmdir (tmp_dir); - g_free (tmp_dir); - tmp_dir = NULL; + g_clear_pointer (&tmp_dir, g_free); } /** diff --git a/libdocument/ev-form-field.c b/libdocument/ev-form-field.c index 23dd2f64..7723ba27 100644 --- a/libdocument/ev-form-field.c +++ b/libdocument/ev-form-field.c @@ -64,9 +64,7 @@ ev_form_field_finalize (GObject *object) EvFormField *field = EV_FORM_FIELD (object); EvFormFieldPrivate *priv = GET_FIELD_PRIVATE (field); - g_object_unref (field->page); - field->page = NULL; - + g_clear_object (&field->page); g_clear_object (&field->activation_link); g_clear_pointer (&priv->alt_ui_name, g_free); @@ -137,10 +135,7 @@ ev_form_field_text_finalize (GObject *object) { EvFormFieldText *field_text = EV_FORM_FIELD_TEXT (object); - if (field_text->text) { - g_free (field_text->text); - field_text->text = NULL; - } + g_clear_pointer (&field_text->text, g_free); (* G_OBJECT_CLASS (ev_form_field_text_parent_class)->finalize) (object); } @@ -173,15 +168,8 @@ ev_form_field_choice_finalize (GObject *object) { EvFormFieldChoice *field_choice = EV_FORM_FIELD_CHOICE (object); - if (field_choice->selected_items) { - g_list_free (field_choice->selected_items); - field_choice->selected_items = NULL; - } - - if (field_choice->text) { - g_free (field_choice->text); - field_choice->text = NULL; - } + g_clear_pointer (&field_choice->selected_items, g_list_free); + g_clear_pointer (&field_choice->text, g_free); (* G_OBJECT_CLASS (ev_form_field_choice_parent_class)->finalize) (object); } diff --git a/libdocument/ev-image.c b/libdocument/ev-image.c index 58309f56..d189b452 100644 --- a/libdocument/ev-image.c +++ b/libdocument/ev-image.c @@ -40,10 +40,7 @@ ev_image_finalize (GObject *object) { EvImage *image = EV_IMAGE (object); - if (image->priv->pixbuf) { - g_object_unref (image->priv->pixbuf); - image->priv->pixbuf = NULL; - } + g_clear_object (&image->priv->pixbuf); if (image->priv->tmp_uri) { gchar *filename; @@ -51,8 +48,7 @@ ev_image_finalize (GObject *object) filename = g_filename_from_uri (image->priv->tmp_uri, NULL, NULL); ev_tmp_filename_unlink (filename); g_free (filename); - g_free (image->priv->tmp_uri); - image->priv->tmp_uri = NULL; + g_clear_pointer (&image->priv->tmp_uri, g_free); } (* G_OBJECT_CLASS (ev_image_parent_class)->finalize) (object); diff --git a/libdocument/ev-link-action.c b/libdocument/ev-link-action.c index da28f5f2..20589bcf 100644 --- a/libdocument/ev-link-action.c +++ b/libdocument/ev-link-action.c @@ -302,48 +302,15 @@ ev_link_action_finalize (GObject *object) g_clear_object (&priv->dest); - if (priv->uri) { - g_free (priv->uri); - priv->uri = NULL; - } + g_clear_pointer (&priv->uri, g_free); + g_clear_pointer (&priv->filename, g_free); + g_clear_pointer (&priv->params, g_free); + g_clear_pointer (&priv->name, g_free); - if (priv->filename) { - g_free (priv->filename); - priv->filename = NULL; - } - - if (priv->params) { - g_free (priv->params); - priv->params = NULL; - } - - if (priv->name) { - g_free (priv->name); - priv->name = NULL; - } - - if (priv->show_list) { - g_list_foreach (priv->show_list, (GFunc)g_object_unref, NULL); - g_list_free (priv->show_list); - priv->show_list = NULL; - } - - if (priv->hide_list) { - g_list_foreach (priv->hide_list, (GFunc)g_object_unref, NULL); - g_list_free (priv->hide_list); - priv->hide_list = NULL; - } - - if (priv->toggle_list) { - g_list_foreach (priv->toggle_list, (GFunc)g_object_unref, NULL); - g_list_free (priv->toggle_list); - priv->toggle_list = NULL; - } - - if (priv->reset_fields) { - g_list_free_full (priv->reset_fields, g_free); - priv->reset_fields = NULL; - } + g_list_free_full (g_steal_pointer (&priv->show_list), g_object_unref); + g_list_free_full (g_steal_pointer (&priv->hide_list), g_object_unref); + g_list_free_full (g_steal_pointer (&priv->toggle_list), g_object_unref); + g_list_free_full (g_steal_pointer (&priv->reset_fields), g_free); G_OBJECT_CLASS (ev_link_action_parent_class)->finalize (object); } diff --git a/libdocument/ev-link-dest.c b/libdocument/ev-link-dest.c index f974fdd3..61b6c7a1 100644 --- a/libdocument/ev-link-dest.c +++ b/libdocument/ev-link-dest.c @@ -255,14 +255,8 @@ ev_link_dest_finalize (GObject *object) priv = EV_LINK_DEST (object)->priv; - if (priv->named) { - g_free (priv->named); - priv->named = NULL; - } - if (priv->page_label) { - g_free (priv->page_label); - priv->page_label = NULL; - } + g_clear_pointer (&priv->named, g_free); + g_clear_pointer (&priv->page_label, g_free); G_OBJECT_CLASS (ev_link_dest_parent_class)->finalize (object); } diff --git a/libdocument/ev-link.c b/libdocument/ev-link.c index 877be6a5..22fc81e6 100644 --- a/libdocument/ev-link.c +++ b/libdocument/ev-link.c @@ -120,11 +120,7 @@ ev_link_finalize (GObject *object) priv = EV_LINK (object)->priv; - if (priv->title) { - g_free (priv->title); - priv->title = NULL; - } - + g_clear_pointer (&priv->title, g_free); g_clear_object (&priv->action); G_OBJECT_CLASS (ev_link_parent_class)->finalize (object); diff --git a/libdocument/ev-module.c b/libdocument/ev-module.c index 71a05d24..b33c3fcc 100644 --- a/libdocument/ev-module.c +++ b/libdocument/ev-module.c @@ -119,8 +119,7 @@ ev_module_unload (GTypeModule *gmodule) { EvModule *module = EV_MODULE (gmodule); - g_module_close (module->library); - module->library = NULL; + g_clear_pointer (&module->library, g_module_close); } const gchar * diff --git a/libdocument/ev-render-context.c b/libdocument/ev-render-context.c index 11bdf098..0adc04d2 100644 --- a/libdocument/ev-render-context.c +++ b/libdocument/ev-render-context.c @@ -36,10 +36,7 @@ ev_render_context_dispose (GObject *object) rc = (EvRenderContext *) object; - if (rc->page) { - g_object_unref (rc->page); - rc->page = NULL; - } + g_clear_object (&rc->page); (* G_OBJECT_CLASS (ev_render_context_parent_class)->dispose) (object); }