From de568a0f61c6f867e09c13336960ca5dcf5b48b1 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Mon, 27 May 2019 17:47:55 +0200 Subject: [PATCH] app: use g_clear_pointer() in more places (cherry picked from commit 901350ba20be52c87469b997be104866fea80215) --- app/config/gimplangrc.c | 7 +-- app/core/gimpbrushpipe.c | 3 +- app/core/gimpchannel.c | 21 ++----- app/core/gimpcurve.c | 16 ++--- app/core/gimphistogram.c | 3 +- app/core/gimplayer.c | 3 +- app/core/gimpmybrush.c | 6 +- app/core/gimpviewable.c | 3 +- app/display/gimpcanvasboundary.c | 14 +---- app/display/gimpcanvaspolygon.c | 17 ++---- app/display/gimpcanvasprogress.c | 6 +- app/display/gimptoolrectangle.c | 6 +- app/pdb/gimpprocedure.c | 6 +- app/text/gimptext.c | 30 ++-------- app/tools/gimpeditselectiontool.c | 29 ++------- app/tools/gimptextoptions.c | 6 +- app/tools/gimptexttool-editor.c | 3 +- app/widgets/gimpactiongroup.c | 13 +--- app/widgets/gimpactionview.c | 3 +- app/widgets/gimpcolorhistory.c | 83 +++++++++++++------------- app/widgets/gimpdockable.c | 31 ++-------- app/widgets/gimpfiledialog.c | 24 ++------ app/widgets/gimpimageparasiteview.c | 7 +-- app/widgets/gimplanguageentry.c | 6 +- app/widgets/gimpmessagebox.c | 10 ++-- app/widgets/gimpoverlaydialog.c | 13 +--- app/widgets/gimpsearchpopup.c | 3 +- app/widgets/gimpsessioninfo-dock.c | 6 +- app/widgets/gimpsessioninfo-dockable.c | 6 +- app/widgets/gimpstringaction.c | 6 +- app/widgets/gimptagentry.c | 6 +- app/widgets/gimptagpopup.c | 3 +- app/widgets/gimptooleditor.c | 3 +- app/widgets/gimpuimanager.c | 10 +--- app/widgets/gimpviewablebutton.c | 20 +------ 35 files changed, 115 insertions(+), 317 deletions(-) diff --git a/app/config/gimplangrc.c b/app/config/gimplangrc.c index 597ebcf5b4..34e26f47ab 100644 --- a/app/config/gimplangrc.c +++ b/app/config/gimplangrc.c @@ -149,11 +149,8 @@ gimp_lang_rc_finalize (GObject *object) g_clear_object (&rc->system_gimprc); g_clear_object (&rc->user_gimprc); - if (rc->language) - { - g_free (rc->language); - rc->language = NULL; - } + + g_clear_pointer (&rc->language, g_free); G_OBJECT_CLASS (parent_class)->finalize (object); } diff --git a/app/core/gimpbrushpipe.c b/app/core/gimpbrushpipe.c index 6d1aa02ed5..cca68adf93 100644 --- a/app/core/gimpbrushpipe.c +++ b/app/core/gimpbrushpipe.c @@ -121,8 +121,7 @@ gimp_brush_pipe_finalize (GObject *object) if (pipe->brushes[i]) g_object_unref (pipe->brushes[i]); - g_free (pipe->brushes); - pipe->brushes = NULL; + g_clear_pointer (&pipe->brushes, g_free); } GIMP_BRUSH (pipe)->priv->mask = NULL; diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c index e3f37d8f43..ba392754d2 100644 --- a/app/core/gimpchannel.c +++ b/app/core/gimpchannel.c @@ -348,17 +348,8 @@ gimp_channel_finalize (GObject *object) { GimpChannel *channel = GIMP_CHANNEL (object); - if (channel->segs_in) - { - g_free (channel->segs_in); - channel->segs_in = NULL; - } - - if (channel->segs_out) - { - g_free (channel->segs_out); - channel->segs_out = NULL; - } + g_clear_pointer (&channel->segs_in, g_free); + g_clear_pointer (&channel->segs_out, g_free); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -1163,14 +1154,10 @@ gimp_channel_real_is_empty (GimpChannel *channel) return FALSE; /* The mask is empty, meaning we can set the bounds as known */ - if (channel->segs_in) - g_free (channel->segs_in); - if (channel->segs_out) - g_free (channel->segs_out); + g_clear_pointer (&channel->segs_in, g_free); + g_clear_pointer (&channel->segs_out, g_free); channel->empty = TRUE; - channel->segs_in = NULL; - channel->segs_out = NULL; channel->num_segs_in = 0; channel->num_segs_out = 0; channel->bounds_known = TRUE; diff --git a/app/core/gimpcurve.c b/app/core/gimpcurve.c index ee57391164..f7daa0b334 100644 --- a/app/core/gimpcurve.c +++ b/app/core/gimpcurve.c @@ -224,17 +224,11 @@ gimp_curve_finalize (GObject *object) { GimpCurve *curve = GIMP_CURVE (object); - if (curve->points) - { - g_free (curve->points); - curve->points = NULL; - } + g_clear_pointer (&curve->points, g_free); + curve->n_points = 0; - if (curve->samples) - { - g_free (curve->samples); - curve->samples = NULL; - } + g_clear_pointer (&curve->samples, g_free); + curve->n_samples = 0; G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -1043,8 +1037,8 @@ gimp_curve_clear_points (GimpCurve *curve) if (curve->points) { - curve->n_points = 0; g_clear_pointer (&curve->points, g_free); + curve->n_points = 0; g_object_notify (G_OBJECT (curve), "n-points"); g_object_notify (G_OBJECT (curve), "points"); diff --git a/app/core/gimphistogram.c b/app/core/gimphistogram.c index 134633e0b0..0abe467412 100644 --- a/app/core/gimphistogram.c +++ b/app/core/gimphistogram.c @@ -370,8 +370,7 @@ gimp_histogram_clear_values (GimpHistogram *histogram) if (histogram->priv->values) { - g_free (histogram->priv->values); - histogram->priv->values = NULL; + g_clear_pointer (&histogram->priv->values, g_free); g_object_notify (G_OBJECT (histogram), "values"); } diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c index ff6f40838c..af4abbf3d2 100644 --- a/app/core/gimplayer.c +++ b/app/core/gimplayer.c @@ -2457,8 +2457,7 @@ gimp_layer_set_floating_sel_drawable (GimpLayer *layer, { if (layer->fs.segs) { - g_free (layer->fs.segs); - layer->fs.segs = NULL; + g_clear_pointer (&layer->fs.segs, g_free); layer->fs.num_segs = 0; } diff --git a/app/core/gimpmybrush.c b/app/core/gimpmybrush.c index b140b13abc..a26c86b227 100644 --- a/app/core/gimpmybrush.c +++ b/app/core/gimpmybrush.c @@ -109,11 +109,7 @@ gimp_mybrush_finalize (GObject *object) { GimpMybrush *brush = GIMP_MYBRUSH (object); - if (brush->priv->brush_json) - { - g_free (brush->priv->brush_json); - brush->priv->brush_json = NULL; - } + g_clear_pointer (&brush->priv->brush_json, g_free); G_OBJECT_CLASS (parent_class)->finalize (object); } diff --git a/app/core/gimpviewable.c b/app/core/gimpviewable.c index 3431cb7385..9092dcd2e1 100644 --- a/app/core/gimpviewable.c +++ b/app/core/gimpviewable.c @@ -1256,8 +1256,7 @@ gimp_viewable_set_icon_name (GimpViewable *viewable, private = GET_PRIVATE (viewable); - g_free (private->icon_name); - private->icon_name = NULL; + g_clear_pointer (&private->icon_name, g_free); viewable_class = GIMP_VIEWABLE_GET_CLASS (viewable); diff --git a/app/display/gimpcanvasboundary.c b/app/display/gimpcanvasboundary.c index b2e445fd2c..a6cab9d150 100644 --- a/app/display/gimpcanvasboundary.c +++ b/app/display/gimpcanvasboundary.c @@ -130,18 +130,10 @@ gimp_canvas_boundary_finalize (GObject *object) { GimpCanvasBoundaryPrivate *private = GET_PRIVATE (object); - if (private->segs) - { - g_free (private->segs); - private->segs = NULL; - private->n_segs = 0; - } + g_clear_pointer (&private->segs, g_free); + private->n_segs = 0; - if (private->transform) - { - g_free (private->transform); - private->transform = NULL; - } + g_clear_pointer (&private->transform, g_free); G_OBJECT_CLASS (parent_class)->finalize (object); } diff --git a/app/display/gimpcanvaspolygon.c b/app/display/gimpcanvaspolygon.c index b4bf5f6183..9c670e78fe 100644 --- a/app/display/gimpcanvaspolygon.c +++ b/app/display/gimpcanvaspolygon.c @@ -121,18 +121,10 @@ gimp_canvas_polygon_finalize (GObject *object) { GimpCanvasPolygonPrivate *private = GET_PRIVATE (object); - if (private->points) - { - g_free (private->points); - private->points = NULL; - private->n_points = 0; - } + g_clear_pointer (&private->points, g_free); + private->n_points = 0; - if (private->transform) - { - g_free (private->transform); - private->transform = NULL; - } + g_clear_pointer (&private->transform, g_free); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -151,8 +143,7 @@ gimp_canvas_polygon_set_property (GObject *object, { GimpArray *array = g_value_get_boxed (value); - g_free (private->points); - private->points = NULL; + g_clear_pointer (&private->points, g_free); private->n_points = 0; if (array) diff --git a/app/display/gimpcanvasprogress.c b/app/display/gimpcanvasprogress.c index 8995d40e6c..4def1ac1ed 100644 --- a/app/display/gimpcanvasprogress.c +++ b/app/display/gimpcanvasprogress.c @@ -173,11 +173,7 @@ gimp_canvas_progress_finalize (GObject *object) { GimpCanvasProgressPrivate *private = GET_PRIVATE (object); - if (private->text) - { - g_free (private->text); - private->text = NULL; - } + g_clear_pointer (&private->text, g_free); G_OBJECT_CLASS (parent_class)->finalize (object); } diff --git a/app/display/gimptoolrectangle.c b/app/display/gimptoolrectangle.c index 309cf8cd48..c0c3a3ef7e 100644 --- a/app/display/gimptoolrectangle.c +++ b/app/display/gimptoolrectangle.c @@ -819,11 +819,7 @@ gimp_tool_rectangle_finalize (GObject *object) GimpToolRectangle *rectangle = GIMP_TOOL_RECTANGLE (object); GimpToolRectanglePrivate *private = rectangle->private; - if (private->status_title) - { - g_free (private->status_title); - private->status_title = NULL; - } + g_clear_pointer (&private->status_title, g_free); G_OBJECT_CLASS (parent_class)->finalize (object); } diff --git a/app/pdb/gimpprocedure.c b/app/pdb/gimpprocedure.c index 6b7ab9789c..a12dab9889 100644 --- a/app/pdb/gimpprocedure.c +++ b/app/pdb/gimpprocedure.c @@ -120,8 +120,7 @@ gimp_procedure_finalize (GObject *object) for (i = 0; i < procedure->num_args; i++) g_param_spec_unref (procedure->args[i]); - g_free (procedure->args); - procedure->args = NULL; + g_clear_pointer (&procedure->args, g_free); } if (procedure->values) @@ -129,8 +128,7 @@ gimp_procedure_finalize (GObject *object) for (i = 0; i < procedure->num_values; i++) g_param_spec_unref (procedure->values[i]); - g_free (procedure->values); - procedure->values = NULL; + g_clear_pointer (&procedure->values, g_free); } G_OBJECT_CLASS (parent_class)->finalize (object); diff --git a/app/text/gimptext.c b/app/text/gimptext.c index 3d808797bd..fe671a42ba 100644 --- a/app/text/gimptext.c +++ b/app/text/gimptext.c @@ -318,26 +318,10 @@ gimp_text_finalize (GObject *object) { GimpText *text = GIMP_TEXT (object); - if (text->text) - { - g_free (text->text); - text->text = NULL; - } - if (text->markup) - { - g_free (text->markup); - text->markup = NULL; - } - if (text->font) - { - g_free (text->font); - text->font = NULL; - } - if (text->language) - { - g_free (text->language); - text->language = NULL; - } + g_clear_pointer (&text->text, g_free); + g_clear_pointer (&text->markup, g_free); + g_clear_pointer (&text->font, g_free); + g_clear_pointer (&text->language, g_free); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -448,8 +432,7 @@ gimp_text_set_property (GObject *object, text->text = g_value_dup_string (value); if (text->text && text->markup) { - g_free (text->markup); - text->markup = NULL; + g_clear_pointer (&text->markup, g_free); g_object_notify (object, "markup"); } break; @@ -458,8 +441,7 @@ gimp_text_set_property (GObject *object, text->markup = g_value_dup_string (value); if (text->markup && text->text) { - g_free (text->text); - text->text = NULL; + g_clear_pointer (&text->text, g_free); g_object_notify (object, "text"); } break; diff --git a/app/tools/gimpeditselectiontool.c b/app/tools/gimpeditselectiontool.c index ec7231bfa2..5a235806eb 100644 --- a/app/tools/gimpeditselectiontool.c +++ b/app/tools/gimpeditselectiontool.c @@ -186,31 +186,14 @@ gimp_edit_selection_tool_finalize (GObject *object) { GimpEditSelectionTool *edit_select = GIMP_EDIT_SELECTION_TOOL (object); - if (edit_select->segs_in) - { - g_free (edit_select->segs_in); - edit_select->segs_in = NULL; - edit_select->num_segs_in = 0; - } + g_clear_pointer (&edit_select->segs_in, g_free); + edit_select->num_segs_in = 0; - if (edit_select->segs_out) - { - g_free (edit_select->segs_out); - edit_select->segs_out = NULL; - edit_select->num_segs_out = 0; - } + g_clear_pointer (&edit_select->segs_out, g_free); + edit_select->num_segs_out = 0; - if (edit_select->live_items) - { - g_list_free (edit_select->live_items); - edit_select->live_items = NULL; - } - - if (edit_select->delayed_items) - { - g_list_free (edit_select->delayed_items); - edit_select->delayed_items = NULL; - } + g_clear_pointer (&edit_select->live_items, g_list_free); + g_clear_pointer (&edit_select->delayed_items, g_list_free); G_OBJECT_CLASS (parent_class)->finalize (object); } diff --git a/app/tools/gimptextoptions.c b/app/tools/gimptextoptions.c index 27a01deddf..70f2dc45c3 100644 --- a/app/tools/gimptextoptions.c +++ b/app/tools/gimptextoptions.c @@ -245,11 +245,7 @@ gimp_text_options_finalize (GObject *object) { GimpTextOptions *options = GIMP_TEXT_OPTIONS (object); - if (options->language) - { - g_free (options->language); - options->language = NULL; - } + g_clear_pointer (&options->language, g_free); G_OBJECT_CLASS (parent_class)->finalize (object); } diff --git a/app/tools/gimptexttool-editor.c b/app/tools/gimptexttool-editor.c index db7fb3ba11..62ee118fed 100644 --- a/app/tools/gimptexttool-editor.c +++ b/app/tools/gimptexttool-editor.c @@ -1711,8 +1711,7 @@ gimp_text_tool_im_delete_preedit (GimpTextTool *text_tool) text_tool->preedit_end = NULL; } - g_free (text_tool->preedit_string); - text_tool->preedit_string = NULL; + g_clear_pointer (&text_tool->preedit_string, g_free); } } diff --git a/app/widgets/gimpactiongroup.c b/app/widgets/gimpactiongroup.c index b81f73bc23..0898db5a13 100644 --- a/app/widgets/gimpactiongroup.c +++ b/app/widgets/gimpactiongroup.c @@ -190,17 +190,8 @@ gimp_action_group_finalize (GObject *object) { GimpActionGroup *group = GIMP_ACTION_GROUP (object); - if (group->label) - { - g_free (group->label); - group->label = NULL; - } - - if (group->icon_name) - { - g_free (group->icon_name); - group->icon_name = NULL; - } + g_clear_pointer (&group->label, g_free); + g_clear_pointer (&group->icon_name, g_free); G_OBJECT_CLASS (parent_class)->finalize (object); } diff --git a/app/widgets/gimpactionview.c b/app/widgets/gimpactionview.c index a4d8ed51d3..362f24a12f 100644 --- a/app/widgets/gimpactionview.c +++ b/app/widgets/gimpactionview.c @@ -423,8 +423,7 @@ gimp_action_view_set_filter (GimpActionView *view, if (filter && ! strlen (filter)) filter = NULL; - g_free (view->filter); - view->filter = NULL; + g_clear_pointer (&view->filter, g_free); if (filter) view->filter = g_utf8_casefold (filter, -1); diff --git a/app/widgets/gimpcolorhistory.c b/app/widgets/gimpcolorhistory.c index c277b25c43..9a9f38a7c0 100644 --- a/app/widgets/gimpcolorhistory.c +++ b/app/widgets/gimpcolorhistory.c @@ -147,8 +147,7 @@ gimp_color_history_finalize (GObject *object) { GimpColorHistory *history = GIMP_COLOR_HISTORY (object); - g_free (history->color_areas); - history->color_areas = NULL; + g_clear_pointer (&history->color_areas, g_free); G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -167,52 +166,52 @@ gimp_color_history_set_property (GObject *object, history->context = g_value_get_object (value); break; case PROP_HISTORY_SIZE: - { - GtkWidget *button; - gint i; + { + GtkWidget *button; + gint i; - /* Destroy previous color buttons. */ - gtk_container_foreach (GTK_CONTAINER (history), - (GtkCallback) gtk_widget_destroy, NULL); - history->history_size = g_value_get_int (value); - gtk_table_resize (GTK_TABLE (history), - 2, (history->history_size + 1)/ 2); - gtk_table_set_row_spacings (GTK_TABLE (history), 2); - gtk_table_set_col_spacings (GTK_TABLE (history), 2); - history->color_areas = g_realloc_n (history->color_areas, - history->history_size, - sizeof (GtkWidget*)); - for (i = 0; i < history->history_size; i++) - { - GimpRGB black = { 0.0, 0.0, 0.0, 1.0 }; - gint row, column; + /* Destroy previous color buttons. */ + gtk_container_foreach (GTK_CONTAINER (history), + (GtkCallback) gtk_widget_destroy, NULL); + history->history_size = g_value_get_int (value); + gtk_table_resize (GTK_TABLE (history), + 2, (history->history_size + 1)/ 2); + gtk_table_set_row_spacings (GTK_TABLE (history), 2); + gtk_table_set_col_spacings (GTK_TABLE (history), 2); + history->color_areas = g_realloc_n (history->color_areas, + history->history_size, + sizeof (GtkWidget*)); + for (i = 0; i < history->history_size; i++) + { + GimpRGB black = { 0.0, 0.0, 0.0, 1.0 }; + gint row, column; - column = i % (history->history_size / 2); - row = i / (history->history_size / 2); + column = i % (history->history_size / 2); + row = i / (history->history_size / 2); - button = gtk_button_new (); - gtk_widget_set_size_request (button, COLOR_AREA_SIZE, COLOR_AREA_SIZE); - gtk_table_attach_defaults (GTK_TABLE (history), button, - column, column + 1, row, row + 1); - gtk_widget_show (button); + button = gtk_button_new (); + gtk_widget_set_size_request (button, COLOR_AREA_SIZE, COLOR_AREA_SIZE); + gtk_table_attach_defaults (GTK_TABLE (history), button, + column, column + 1, row, row + 1); + gtk_widget_show (button); - history->color_areas[i] = gimp_color_area_new (&black, - GIMP_COLOR_AREA_SMALL_CHECKS, - GDK_BUTTON2_MASK); - gimp_color_area_set_color_config (GIMP_COLOR_AREA (history->color_areas[i]), - history->context->gimp->config->color_management); - gtk_container_add (GTK_CONTAINER (button), history->color_areas[i]); - gtk_widget_show (history->color_areas[i]); + history->color_areas[i] = gimp_color_area_new (&black, + GIMP_COLOR_AREA_SMALL_CHECKS, + GDK_BUTTON2_MASK); + gimp_color_area_set_color_config (GIMP_COLOR_AREA (history->color_areas[i]), + history->context->gimp->config->color_management); + gtk_container_add (GTK_CONTAINER (button), history->color_areas[i]); + gtk_widget_show (history->color_areas[i]); - g_signal_connect (button, "clicked", - G_CALLBACK (gimp_color_history_color_clicked), - history); + g_signal_connect (button, "clicked", + G_CALLBACK (gimp_color_history_color_clicked), + history); - g_signal_connect (history->color_areas[i], "color-changed", - G_CALLBACK (gimp_color_history_color_changed), - GINT_TO_POINTER (i)); - } - } + g_signal_connect (history->color_areas[i], "color-changed", + G_CALLBACK (gimp_color_history_color_changed), + GINT_TO_POINTER (i)); + } + } break; default: diff --git a/app/widgets/gimpdockable.c b/app/widgets/gimpdockable.c index 0b5278aa7e..0bce4726a1 100644 --- a/app/widgets/gimpdockable.c +++ b/app/widgets/gimpdockable.c @@ -200,31 +200,10 @@ gimp_dockable_dispose (GObject *object) if (dockable->p->context) gimp_dockable_set_context (dockable, NULL); - if (dockable->p->blurb) - { - if (dockable->p->blurb != dockable->p->name) - g_free (dockable->p->blurb); - - dockable->p->blurb = NULL; - } - - if (dockable->p->name) - { - g_free (dockable->p->name); - dockable->p->name = NULL; - } - - if (dockable->p->icon_name) - { - g_free (dockable->p->icon_name); - dockable->p->icon_name = NULL; - } - - if (dockable->p->help_id) - { - g_free (dockable->p->help_id); - dockable->p->help_id = NULL; - } + g_clear_pointer (&dockable->p->blurb, g_free); + g_clear_pointer (&dockable->p->name, g_free); + g_clear_pointer (&dockable->p->icon_name, g_free); + g_clear_pointer (&dockable->p->help_id, g_free); G_OBJECT_CLASS (parent_class)->dispose (object); } @@ -545,7 +524,7 @@ gimp_dockable_new (const gchar *name, if (blurb) dockable->p->blurb = g_strdup (blurb); else - dockable->p->blurb = dockable->p->name; + dockable->p->blurb = g_strdup (dockable->p->name); gimp_help_set_help_data (GTK_WIDGET (dockable), NULL, help_id); diff --git a/app/widgets/gimpfiledialog.c b/app/widgets/gimpfiledialog.c index 6f96eb623d..4e48e65450 100644 --- a/app/widgets/gimpfiledialog.c +++ b/app/widgets/gimpfiledialog.c @@ -395,25 +395,11 @@ gimp_file_dialog_dispose (GObject *object) dialog->progress = NULL; - if (dialog->help_id) - g_free (dialog->help_id); - dialog->help_id = NULL; - - if (dialog->ok_button_label) - g_free (dialog->ok_button_label); - dialog->ok_button_label = NULL; - - if (dialog->automatic_help_id) - g_free (dialog->automatic_help_id); - dialog->automatic_help_id = NULL; - - if (dialog->automatic_label) - g_free (dialog->automatic_label); - dialog->automatic_label = NULL; - - if (dialog->file_filter_label) - g_free (dialog->file_filter_label); - dialog->file_filter_label = NULL; + g_clear_pointer (&dialog->help_id, g_free); + g_clear_pointer (&dialog->ok_button_label, g_free); + g_clear_pointer (&dialog->automatic_help_id, g_free); + g_clear_pointer (&dialog->automatic_label, g_free); + g_clear_pointer (&dialog->file_filter_label, g_free); } static gboolean diff --git a/app/widgets/gimpimageparasiteview.c b/app/widgets/gimpimageparasiteview.c index 8c87fef7de..76e060d97d 100644 --- a/app/widgets/gimpimageparasiteview.c +++ b/app/widgets/gimpimageparasiteview.c @@ -143,12 +143,7 @@ gimp_image_parasite_view_finalize (GObject *object) { GimpImageParasiteView *view = GIMP_IMAGE_PARASITE_VIEW (object); - if (view->parasite) - { - g_free (view->parasite); - view->parasite = NULL; - - } + g_clear_pointer (&view->parasite, g_free); G_OBJECT_CLASS (parent_class)->finalize (object); } diff --git a/app/widgets/gimplanguageentry.c b/app/widgets/gimplanguageentry.c index e36f3a85b9..389651898c 100644 --- a/app/widgets/gimplanguageentry.c +++ b/app/widgets/gimplanguageentry.c @@ -226,11 +226,7 @@ gimp_language_entry_set_code (GimpLanguageEntry *entry, g_return_val_if_fail (GIMP_IS_LANGUAGE_ENTRY (entry), FALSE); - if (entry->code) - { - g_free (entry->code); - entry->code = NULL; - } + g_clear_pointer (&entry->code, g_free); if (! code || ! strlen (code)) { diff --git a/app/widgets/gimpmessagebox.c b/app/widgets/gimpmessagebox.c index 77499fed0a..a9fa8647f6 100644 --- a/app/widgets/gimpmessagebox.c +++ b/app/widgets/gimpmessagebox.c @@ -188,15 +188,13 @@ gimp_message_box_finalize (GObject *object) GimpMessageBox *box = GIMP_MESSAGE_BOX (object); if (box->idle_id) - g_source_remove (box->idle_id); - box->idle_id = 0; - - if (box->icon_name) { - g_free (box->icon_name); - box->icon_name = NULL; + g_source_remove (box->idle_id); + box->idle_id = 0; } + g_clear_pointer (&box->icon_name, g_free); + G_OBJECT_CLASS (parent_class)->finalize (object); } diff --git a/app/widgets/gimpoverlaydialog.c b/app/widgets/gimpoverlaydialog.c index a3a3c02272..4195323619 100644 --- a/app/widgets/gimpoverlaydialog.c +++ b/app/widgets/gimpoverlaydialog.c @@ -265,17 +265,8 @@ gimp_overlay_dialog_finalize (GObject *object) { GimpOverlayDialog *dialog = GIMP_OVERLAY_DIALOG (object); - if (dialog->title) - { - g_free (dialog->title); - dialog->title = NULL; - } - - if (dialog->icon_name) - { - g_free (dialog->icon_name); - dialog->icon_name = NULL; - } + g_clear_pointer (&dialog->title, g_free); + g_clear_pointer (&dialog->icon_name, g_free); G_OBJECT_CLASS (parent_class)->finalize (object); } diff --git a/app/widgets/gimpsearchpopup.c b/app/widgets/gimpsearchpopup.c index 4a5a8ecdab..b085687919 100644 --- a/app/widgets/gimpsearchpopup.c +++ b/app/widgets/gimpsearchpopup.c @@ -755,8 +755,7 @@ gimp_search_popup_find_accel_label (GtkAction *action) /* The value returned by gtk_accelerator_get_label() must be * freed after use. */ - g_free (accel_string); - accel_string = NULL; + g_clear_pointer (&accel_string, g_free); } return accel_string; diff --git a/app/widgets/gimpsessioninfo-dock.c b/app/widgets/gimpsessioninfo-dock.c index 281098c023..9948074aac 100644 --- a/app/widgets/gimpsessioninfo-dock.c +++ b/app/widgets/gimpsessioninfo-dock.c @@ -88,11 +88,7 @@ gimp_session_info_dock_free (GimpSessionInfoDock *dock_info) { g_return_if_fail (dock_info != NULL); - if (dock_info->dock_type) - { - g_free (dock_info->dock_type); - dock_info->dock_type = NULL; - } + g_clear_pointer (&dock_info->dock_type, g_free); if (dock_info->books) { diff --git a/app/widgets/gimpsessioninfo-dockable.c b/app/widgets/gimpsessioninfo-dockable.c index cd46c6b844..5fa54387f0 100644 --- a/app/widgets/gimpsessioninfo-dockable.c +++ b/app/widgets/gimpsessioninfo-dockable.c @@ -59,11 +59,7 @@ gimp_session_info_dockable_free (GimpSessionInfoDockable *info) { g_return_if_fail (info != NULL); - if (info->identifier) - { - g_free (info->identifier); - info->identifier = NULL; - } + g_clear_pointer (&info->identifier, g_free); if (info->aux_info) { diff --git a/app/widgets/gimpstringaction.c b/app/widgets/gimpstringaction.c index 3d91b1f7d3..d2c844f253 100644 --- a/app/widgets/gimpstringaction.c +++ b/app/widgets/gimpstringaction.c @@ -102,11 +102,7 @@ gimp_string_action_finalize (GObject *object) { GimpStringAction *action = GIMP_STRING_ACTION (object); - if (action->value) - { - g_free (action->value); - action->value = NULL; - } + g_clear_pointer (&action->value, g_free); G_OBJECT_CLASS (parent_class)->finalize (object); } diff --git a/app/widgets/gimptagentry.c b/app/widgets/gimptagentry.c index b68c60161c..85f46b2567 100644 --- a/app/widgets/gimptagentry.c +++ b/app/widgets/gimptagentry.c @@ -220,11 +220,7 @@ gimp_tag_entry_dispose (GObject *object) { GimpTagEntry *entry = GIMP_TAG_ENTRY (object); - if (entry->selected_items) - { - g_list_free (entry->selected_items); - entry->selected_items = NULL; - } + g_clear_pointer (&entry->selected_items, g_list_free); if (entry->common_tags) { diff --git a/app/widgets/gimptagpopup.c b/app/widgets/gimptagpopup.c index b8b3d79fd8..cc7667047b 100644 --- a/app/widgets/gimptagpopup.c +++ b/app/widgets/gimptagpopup.c @@ -381,8 +381,7 @@ gimp_tag_popup_dispose (GObject *object) g_object_unref (popup->tag_data[i].tag); } - g_free (popup->tag_data); - popup->tag_data = NULL; + g_clear_pointer (&popup->tag_data, g_free); } G_OBJECT_CLASS (parent_class)->dispose (object); diff --git a/app/widgets/gimptooleditor.c b/app/widgets/gimptooleditor.c index 1c46067079..68ead5e716 100644 --- a/app/widgets/gimptooleditor.c +++ b/app/widgets/gimptooleditor.c @@ -186,8 +186,7 @@ gimp_tool_editor_finalize (GObject *object) g_free (priv->initial_tool_order[i]); } - g_free (priv->initial_tool_order); - priv->initial_tool_order = NULL; + g_clear_pointer (&priv->initial_tool_order, g_free); } if (priv->initial_tool_visibility) diff --git a/app/widgets/gimpuimanager.c b/app/widgets/gimpuimanager.c index 97f281cb9d..fdae2faf68 100644 --- a/app/widgets/gimpuimanager.c +++ b/app/widgets/gimpuimanager.c @@ -264,14 +264,8 @@ gimp_ui_manager_finalize (GObject *object) g_slice_free (GimpUIManagerUIEntry, entry); } - g_list_free (manager->registered_uis); - manager->registered_uis = NULL; - - if (manager->name) - { - g_free (manager->name); - manager->name = NULL; - } + g_clear_pointer (&manager->registered_uis, g_list_free); + g_clear_pointer (&manager->name, g_free); G_OBJECT_CLASS (parent_class)->finalize (object); } diff --git a/app/widgets/gimpviewablebutton.c b/app/widgets/gimpviewablebutton.c index 0d44756c3e..db4e4ad2d5 100644 --- a/app/widgets/gimpviewablebutton.c +++ b/app/widgets/gimpviewablebutton.c @@ -116,23 +116,9 @@ gimp_viewable_button_finalize (GObject *object) { GimpViewableButton *button = GIMP_VIEWABLE_BUTTON (object); - if (button->dialog_identifier) - { - g_free (button->dialog_identifier); - button->dialog_identifier = NULL; - } - - if (button->dialog_icon_name) - { - g_free (button->dialog_icon_name); - button->dialog_icon_name = NULL; - } - - if (button->dialog_tooltip) - { - g_free (button->dialog_tooltip); - button->dialog_tooltip = NULL; - } + g_clear_pointer (&button->dialog_identifier, g_free); + g_clear_pointer (&button->dialog_icon_name, g_free); + g_clear_pointer (&button->dialog_tooltip, g_free); G_OBJECT_CLASS (parent_class)->finalize (object); }