[gimp] app: use g_clear_pointer() in more places



commit 901350ba20be52c87469b997be104866fea80215
Author: Michael Natterer <mitch gimp org>
Date:   Mon May 27 17:47:55 2019 +0200

    app: use g_clear_pointer() in more places

 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         | 113 +++++++++++++++++----------------
 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, 133 insertions(+), 329 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 e32ef410b4..efc330f4e6 100644
--- a/app/core/gimpchannel.c
+++ b/app/core/gimpchannel.c
@@ -350,17 +350,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);
 }
@@ -1166,14 +1157,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 015577b36f..00d4c7f115 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 16839e9c05..d97468dae3 100644
--- a/app/core/gimplayer.c
+++ b/app/core/gimplayer.c
@@ -2507,8 +2507,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 42f79d46e8..a4bf46ded3 100644
--- a/app/core/gimpviewable.c
+++ b/app/core/gimpviewable.c
@@ -1254,8 +1254,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 a58a197e2c..107541c34c 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 f51beffe7f..6ff5a65f28 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 d97b822615..033631b64f 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 8aabf6b866..d8029678ee 100644
--- a/app/widgets/gimpactionview.c
+++ b/app/widgets/gimpactionview.c
@@ -356,8 +356,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 45354f17b7..8d9ec7282a 100644
--- a/app/widgets/gimpcolorhistory.c
+++ b/app/widgets/gimpcolorhistory.c
@@ -191,10 +191,9 @@ gimp_color_history_finalize (GObject *object)
     g_signal_handlers_disconnect_by_func (history->active_image,
                                           G_CALLBACK (gimp_color_history_palette_dirty),
                                           history);
-  g_free (history->color_areas);
-  history->color_areas = NULL;
-  g_free (history->buttons);
-  history->buttons = NULL;
+
+  g_clear_pointer (&history->color_areas, g_free);
+  g_clear_pointer (&history->buttons,     g_free);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
@@ -214,6 +213,7 @@ gimp_color_history_set_property (GObject      *object,
         g_signal_handlers_disconnect_by_func (history->context,
                                               gimp_color_history_image_changed,
                                               history);
+
       if (history->active_image)
         {
           g_signal_handlers_disconnect_by_func (history->active_image,
@@ -221,13 +221,17 @@ gimp_color_history_set_property (GObject      *object,
                                                 history);
           history->active_image = NULL;
         }
+
       history->context = g_value_get_object (value);
+
       if (history->context)
         {
           g_signal_connect (history->context, "image-changed",
                             G_CALLBACK (gimp_color_history_image_changed),
                             history);
+
           history->active_image = gimp_context_get_image (history->context);
+
           if (history->active_image)
             {
               g_signal_connect_swapped (history->active_image, "notify::base-type",
@@ -241,56 +245,57 @@ gimp_color_history_set_property (GObject      *object,
       break;
 
     case PROP_HISTORY_SIZE:
-        {
-          GtkWidget *button;
-          GtkWidget *color_area;
-          gint       i;
-
-          history->history_size = g_value_get_int (value);
-
-          /* Destroy previous color buttons. */
-          gtk_container_foreach (GTK_CONTAINER (history),
-                                 (GtkCallback) gtk_widget_destroy, NULL);
-          history->buttons = g_realloc_n (history->buttons,
-                                          history->history_size,
-                                          sizeof (GtkWidget*));
-          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 / history->n_rows);
-              row    = i / (history->history_size / history->n_rows);
-
-              button = gtk_button_new ();
-              gtk_widget_set_size_request (button, COLOR_AREA_SIZE, COLOR_AREA_SIZE);
-              gtk_grid_attach (GTK_GRID (history), button, column, row, 1, 1);
-              gtk_widget_show (button);
-
-              color_area = gimp_color_area_new (&black, GIMP_COLOR_AREA_SMALL_CHECKS,
-                                                GDK_BUTTON2_MASK);
-              gimp_color_area_set_color_config (GIMP_COLOR_AREA (color_area),
-                                                history->context->gimp->config->color_management);
-              gtk_container_add (GTK_CONTAINER (button), color_area);
-              gtk_widget_show (color_area);
-
-              g_signal_connect (button, "clicked",
-                                G_CALLBACK (gimp_color_history_color_clicked),
-                                history);
-
-              g_signal_connect (color_area, "color-changed",
-                                G_CALLBACK (gimp_color_history_color_changed),
-                                GINT_TO_POINTER (i));
-
-              history->buttons[i] = button;
-              history->color_areas[i] = color_area;
-            }
-
-          gimp_color_history_palette_dirty (history);
-        }
+      {
+        GtkWidget *button;
+        GtkWidget *color_area;
+        gint       i;
+
+        history->history_size = g_value_get_int (value);
+
+        /* Destroy previous color buttons. */
+        gtk_container_foreach (GTK_CONTAINER (history),
+                               (GtkCallback) gtk_widget_destroy, NULL);
+        history->buttons = g_realloc_n (history->buttons,
+                                        history->history_size,
+                                        sizeof (GtkWidget*));
+        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 / history->n_rows);
+            row    = i / (history->history_size / history->n_rows);
+
+            button = gtk_button_new ();
+            gtk_widget_set_size_request (button, COLOR_AREA_SIZE, COLOR_AREA_SIZE);
+            gtk_grid_attach (GTK_GRID (history), button, column, row, 1, 1);
+            gtk_widget_show (button);
+
+            color_area = gimp_color_area_new (&black, GIMP_COLOR_AREA_SMALL_CHECKS,
+                                              GDK_BUTTON2_MASK);
+            gimp_color_area_set_color_config (GIMP_COLOR_AREA (color_area),
+                                              history->context->gimp->config->color_management);
+            gtk_container_add (GTK_CONTAINER (button), color_area);
+            gtk_widget_show (color_area);
+
+            g_signal_connect (button, "clicked",
+                              G_CALLBACK (gimp_color_history_color_clicked),
+                              history);
+
+            g_signal_connect (color_area, "color-changed",
+                              G_CALLBACK (gimp_color_history_color_changed),
+                              GINT_TO_POINTER (i));
+
+            history->buttons[i]     = button;
+            history->color_areas[i] = color_area;
+          }
+
+        gimp_color_history_palette_dirty (history);
+      }
       break;
 
     default:
diff --git a/app/widgets/gimpdockable.c b/app/widgets/gimpdockable.c
index 890b989ddf..2b55440582 100644
--- a/app/widgets/gimpdockable.c
+++ b/app/widgets/gimpdockable.c
@@ -163,31 +163,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);
 }
@@ -382,7 +361,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 ae403cb240..d679424f5b 100644
--- a/app/widgets/gimpfiledialog.c
+++ b/app/widgets/gimpfiledialog.c
@@ -378,25 +378,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 28bbcec166..5142a39ae6 100644
--- a/app/widgets/gimpmessagebox.c
+++ b/app/widgets/gimpmessagebox.c
@@ -208,15 +208,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 856ca7f3d9..af7e918321 100644
--- a/app/widgets/gimpoverlaydialog.c
+++ b/app/widgets/gimpoverlaydialog.c
@@ -286,17 +286,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 18a81362e6..06cfdab20a 100644
--- a/app/widgets/gimpsearchpopup.c
+++ b/app/widgets/gimpsearchpopup.c
@@ -756,8 +756,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 08e1c1dae9..ef8bed4ae9 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 100ebbd10d..a2c00b0f4e 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 8cfb6a0721..f996bf0c33 100644
--- a/app/widgets/gimptagpopup.c
+++ b/app/widgets/gimptagpopup.c
@@ -391,8 +391,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 1ad4693604..2250dcdc13 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 b17d2a9f8a..043f9bc177 100644
--- a/app/widgets/gimpuimanager.c
+++ b/app/widgets/gimpuimanager.c
@@ -263,14 +263,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);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]