[gimp/gimp-2-10] libgimp*: use more g_clear_pointer()



commit 1af8d2a2c7e3bac5f1811569e1deeee1ee4d03f0
Author: Michael Natterer <mitch gimp org>
Date:   Thu Jul 25 12:37:52 2019 +0200

    libgimp*: use more g_clear_pointer()
    
    (cherry picked from commit c144cf69ded1876ce9af0b0ba0c5a870cb4bc364)

 libgimp/gimpbrushselectbutton.c      | 11 +++------
 libgimp/gimpfontselectbutton.c       |  7 ++----
 libgimp/gimpgradientselectbutton.c   | 11 +++------
 libgimp/gimppaletteselectbutton.c    |  7 ++----
 libgimp/gimppatternselectbutton.c    | 11 +++------
 libgimpbase/gimpvaluearray.c         | 21 +++++++++---------
 libgimpmodule/gimpmodule.c           | 20 +++--------------
 libgimpthumb/gimpthumbnail.c         | 43 ++++++------------------------------
 libgimpwidgets/gimpcontroller.c      | 13 ++---------
 libgimpwidgets/gimpenumlabel.c       |  3 +--
 libgimpwidgets/gimpnumberpairentry.c | 14 +++---------
 libgimpwidgets/gimpunitstore.c       | 22 +++++-------------
 12 files changed, 44 insertions(+), 139 deletions(-)
---
diff --git a/libgimp/gimpbrushselectbutton.c b/libgimp/gimpbrushselectbutton.c
index 45cdee8229..0dc3d540f0 100644
--- a/libgimp/gimpbrushselectbutton.c
+++ b/libgimp/gimpbrushselectbutton.c
@@ -477,14 +477,9 @@ gimp_brush_select_button_finalize (GObject *object)
 
   priv = GIMP_BRUSH_SELECT_BUTTON_GET_PRIVATE (object);
 
-  g_free (priv->brush_name);
-  priv->brush_name = NULL;
-
-  g_free (priv->mask_data);
-  priv->mask_data = NULL;
-
-  g_free (priv->title);
-  priv->title = NULL;
+  g_clear_pointer (&priv->brush_name, g_free);
+  g_clear_pointer (&priv->mask_data,  g_free);
+  g_clear_pointer (&priv->title,      g_free);
 
   G_OBJECT_CLASS (gimp_brush_select_button_parent_class)->finalize (object);
 }
diff --git a/libgimp/gimpfontselectbutton.c b/libgimp/gimpfontselectbutton.c
index f3460f2c87..287b666f51 100644
--- a/libgimp/gimpfontselectbutton.c
+++ b/libgimp/gimpfontselectbutton.c
@@ -277,11 +277,8 @@ gimp_font_select_button_finalize (GObject *object)
 
   priv = GIMP_FONT_SELECT_BUTTON_GET_PRIVATE (object);
 
-  g_free (priv->font_name);
-  priv->font_name = NULL;
-
-  g_free (priv->title);
-  priv->title = NULL;
+  g_clear_pointer (&priv->font_name, g_free);
+  g_clear_pointer (&priv->title,     g_free);
 
   G_OBJECT_CLASS (gimp_font_select_button_parent_class)->finalize (object);
 }
diff --git a/libgimp/gimpgradientselectbutton.c b/libgimp/gimpgradientselectbutton.c
index 25e6a8ce44..fac6e3a167 100644
--- a/libgimp/gimpgradientselectbutton.c
+++ b/libgimp/gimpgradientselectbutton.c
@@ -330,14 +330,9 @@ gimp_gradient_select_button_finalize (GObject *object)
 
   priv = GIMP_GRADIENT_SELECT_BUTTON_GET_PRIVATE (object);
 
-  g_free (priv->gradient_name);
-  priv->gradient_name = NULL;
-
-  g_free (priv->gradient_data);
-  priv->gradient_data = NULL;
-
-  g_free (priv->title);
-  priv->title = NULL;
+  g_clear_pointer (&priv->gradient_name, g_free);
+  g_clear_pointer (&priv->gradient_data, g_free);
+  g_clear_pointer (&priv->title,         g_free);
 
   G_OBJECT_CLASS (gimp_gradient_select_button_parent_class)->finalize (object);
 }
diff --git a/libgimp/gimppaletteselectbutton.c b/libgimp/gimppaletteselectbutton.c
index 66ddd688e9..ad4957f968 100644
--- a/libgimp/gimppaletteselectbutton.c
+++ b/libgimp/gimppaletteselectbutton.c
@@ -292,11 +292,8 @@ gimp_palette_select_button_finalize (GObject *object)
 
   priv = GIMP_PALETTE_SELECT_BUTTON_GET_PRIVATE (object);
 
-  g_free (priv->palette_name);
-  priv->palette_name = NULL;
-
-  g_free (priv->title);
-  priv->title = NULL;
+  g_clear_pointer (&priv->palette_name, g_free);
+  g_clear_pointer (&priv->title,        g_free);
 
   G_OBJECT_CLASS (gimp_palette_select_button_parent_class)->finalize (object);
 }
diff --git a/libgimp/gimppatternselectbutton.c b/libgimp/gimppatternselectbutton.c
index ea652eb10b..af37fad1f1 100644
--- a/libgimp/gimppatternselectbutton.c
+++ b/libgimp/gimppatternselectbutton.c
@@ -350,14 +350,9 @@ gimp_pattern_select_button_finalize (GObject *object)
 
   priv = GIMP_PATTERN_SELECT_BUTTON_GET_PRIVATE (object);
 
-  g_free (priv->pattern_name);
-  priv->pattern_name = NULL;
-
-  g_free (priv->mask_data);
-  priv->mask_data = NULL;
-
-  g_free (priv->title);
-  priv->title = NULL;
+  g_clear_pointer (&priv->pattern_name, g_free);
+  g_clear_pointer (&priv->mask_data,    g_free);
+  g_clear_pointer (&priv->title,        g_free);
 
   G_OBJECT_CLASS (gimp_pattern_select_button_parent_class)->finalize (object);
 }
diff --git a/libgimpbase/gimpvaluearray.c b/libgimpbase/gimpvaluearray.c
index 6643ea85bc..eb23b82a70 100644
--- a/libgimpbase/gimpvaluearray.c
+++ b/libgimpbase/gimpvaluearray.c
@@ -195,6 +195,7 @@ gimp_value_array_unref (GimpValueArray *value_array)
           if (G_VALUE_TYPE (value) != 0) /* we allow unset values in the array */
             g_value_unset (value);
         }
+
       g_free (value_array->values);
       g_slice_free (GimpValueArray, value_array);
     }
@@ -430,13 +431,11 @@ static void
 gimp_param_value_array_finalize (GParamSpec *pspec)
 {
   GimpParamSpecValueArray *aspec = GIMP_PARAM_SPEC_VALUE_ARRAY (pspec);
-  GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (GIMP_TYPE_PARAM_VALUE_ARRAY));
+  GParamSpecClass         *parent_class;
 
-  if (aspec->element_spec)
-    {
-      g_param_spec_unref (aspec->element_spec);
-      aspec->element_spec = NULL;
-    }
+  parent_class = g_type_class_peek (g_type_parent (GIMP_TYPE_PARAM_VALUE_ARRAY));
+
+  g_clear_pointer (&aspec->element_spec, g_param_spec_unref);
 
   parent_class->finalize (pspec);
 }
@@ -447,7 +446,7 @@ gimp_param_value_array_set_default (GParamSpec *pspec,
 {
   GimpParamSpecValueArray *aspec = GIMP_PARAM_SPEC_VALUE_ARRAY (pspec);
 
-  if (!value->data[0].v_pointer && aspec->fixed_n_elements)
+  if (! value->data[0].v_pointer && aspec->fixed_n_elements)
     value->data[0].v_pointer = gimp_value_array_new (aspec->fixed_n_elements);
 
   if (value->data[0].v_pointer)
@@ -462,11 +461,11 @@ static gboolean
 gimp_param_value_array_validate (GParamSpec *pspec,
                                  GValue     *value)
 {
-  GimpParamSpecValueArray *aspec = GIMP_PARAM_SPEC_VALUE_ARRAY (pspec);
-  GimpValueArray *value_array = value->data[0].v_pointer;
-  guint changed = 0;
+  GimpParamSpecValueArray *aspec       = GIMP_PARAM_SPEC_VALUE_ARRAY (pspec);
+  GimpValueArray          *value_array = value->data[0].v_pointer;
+  guint                    changed     = 0;
 
-  if (!value->data[0].v_pointer && aspec->fixed_n_elements)
+  if (! value->data[0].v_pointer && aspec->fixed_n_elements)
     value->data[0].v_pointer = gimp_value_array_new (aspec->fixed_n_elements);
 
   if (value->data[0].v_pointer)
diff --git a/libgimpmodule/gimpmodule.c b/libgimpmodule/gimpmodule.c
index 8c36edab14..83a5e90140 100644
--- a/libgimpmodule/gimpmodule.c
+++ b/libgimpmodule/gimpmodule.c
@@ -113,23 +113,9 @@ gimp_module_finalize (GObject *object)
 {
   GimpModule *module = GIMP_MODULE (object);
 
-  if (module->info)
-    {
-      gimp_module_info_free (module->info);
-      module->info = NULL;
-    }
-
-  if (module->last_module_error)
-    {
-      g_free (module->last_module_error);
-      module->last_module_error = NULL;
-    }
-
-  if (module->filename)
-    {
-      g_free (module->filename);
-      module->filename = NULL;
-    }
+  g_clear_pointer (&module->info,              gimp_module_info_free);
+  g_clear_pointer (&module->last_module_error, g_free);
+  g_clear_pointer (&module->filename,          g_free);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
diff --git a/libgimpthumb/gimpthumbnail.c b/libgimpthumb/gimpthumbnail.c
index 69935d42f6..e7f9d3d618 100644
--- a/libgimpthumb/gimpthumbnail.c
+++ b/libgimpthumb/gimpthumbnail.c
@@ -244,31 +244,11 @@ gimp_thumbnail_finalize (GObject *object)
 {
   GimpThumbnail *thumbnail = GIMP_THUMBNAIL (object);
 
-  if (thumbnail->image_uri)
-    {
-      g_free (thumbnail->image_uri);
-      thumbnail->image_uri = NULL;
-    }
-  if (thumbnail->image_filename)
-    {
-      g_free (thumbnail->image_filename);
-      thumbnail->image_filename = NULL;
-    }
-  if (thumbnail->image_mimetype)
-    {
-      g_free (thumbnail->image_mimetype);
-      thumbnail->image_mimetype = NULL;
-    }
-  if (thumbnail->image_type)
-    {
-      g_free (thumbnail->image_type);
-      thumbnail->image_type = NULL;
-    }
-  if (thumbnail->thumb_filename)
-    {
-      g_free (thumbnail->thumb_filename);
-      thumbnail->thumb_filename = NULL;
-    }
+  g_clear_pointer (&thumbnail->image_uri,      g_free);
+  g_clear_pointer (&thumbnail->image_filename, g_free);
+  g_clear_pointer (&thumbnail->image_mimetype, g_free);
+  g_clear_pointer (&thumbnail->image_type,     g_free);
+  g_clear_pointer (&thumbnail->thumb_filename, g_free);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
@@ -405,17 +385,8 @@ gimp_thumbnail_set_uri (GimpThumbnail *thumbnail,
 
   thumbnail->image_uri = g_strdup (uri);
 
-  if (thumbnail->image_filename)
-    {
-      g_free (thumbnail->image_filename);
-      thumbnail->image_filename = NULL;
-    }
-
-  if (thumbnail->thumb_filename)
-    {
-      g_free (thumbnail->thumb_filename);
-      thumbnail->thumb_filename = NULL;
-    }
+  g_clear_pointer (&thumbnail->image_filename, g_free);
+  g_clear_pointer (&thumbnail->thumb_filename, g_free);
 
   thumbnail->thumb_size     = -1;
   thumbnail->thumb_filesize = 0;
diff --git a/libgimpwidgets/gimpcontroller.c b/libgimpwidgets/gimpcontroller.c
index 5eb27fc453..72199df2f8 100644
--- a/libgimpwidgets/gimpcontroller.c
+++ b/libgimpwidgets/gimpcontroller.c
@@ -133,17 +133,8 @@ gimp_controller_finalize (GObject *object)
 {
   GimpController *controller = GIMP_CONTROLLER (object);
 
-  if (controller->name)
-    {
-      g_free (controller->name);
-      controller->name = NULL;
-    }
-
-  if (controller->state)
-    {
-      g_free (controller->state);
-      controller->state = NULL;
-    }
+  g_clear_pointer (&controller->name,  g_free);
+  g_clear_pointer (&controller->state, g_free);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
diff --git a/libgimpwidgets/gimpenumlabel.c b/libgimpwidgets/gimpenumlabel.c
index 5bb6fac808..ad114adcfc 100644
--- a/libgimpwidgets/gimpenumlabel.c
+++ b/libgimpwidgets/gimpenumlabel.c
@@ -113,8 +113,7 @@ gimp_enum_label_finalize (GObject *object)
 {
   GimpEnumLabel *enum_label = GIMP_ENUM_LABEL (object);
 
-  if (enum_label->enum_class)
-    g_type_class_unref (enum_label->enum_class);
+  g_clear_pointer (&enum_label->enum_class, g_type_class_unref);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
diff --git a/libgimpwidgets/gimpnumberpairentry.c b/libgimpwidgets/gimpnumberpairentry.c
index 0b57bb33c5..c41fda7c69 100644
--- a/libgimpwidgets/gimpnumberpairentry.c
+++ b/libgimpwidgets/gimpnumberpairentry.c
@@ -349,18 +349,10 @@ gimp_number_pair_entry_finalize (GObject *object)
 
   priv = GIMP_NUMBER_PAIR_ENTRY_GET_PRIVATE (object);
 
-  if (priv->separators)
-    {
-      g_free (priv->separators);
-      priv->separators     = NULL;
-      priv->num_separators = 0;
-    }
+  g_clear_pointer (&priv->separators, g_free);
+  priv->num_separators = 0;
 
-  if (priv->default_text)
-    {
-      g_free (priv->default_text);
-      priv->default_text = NULL;
-    }
+  g_clear_pointer (&priv->default_text, g_free);
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
diff --git a/libgimpwidgets/gimpunitstore.c b/libgimpwidgets/gimpunitstore.c
index d76c4dc1e7..40ecc972cd 100644
--- a/libgimpwidgets/gimpunitstore.c
+++ b/libgimpwidgets/gimpunitstore.c
@@ -215,24 +215,12 @@ gimp_unit_store_finalize (GObject *object)
 {
   GimpUnitStorePrivate *private = GET_PRIVATE (object);
 
-  if (private->short_format)
-    {
-      g_free (private->short_format);
-      private->short_format = NULL;
-    }
+  g_clear_pointer (&private->short_format, g_free);
+  g_clear_pointer (&private->long_format,  g_free);
 
-  if (private->long_format)
-    {
-      g_free (private->long_format);
-      private->long_format = NULL;
-    }
-
-  if (private->num_values > 0)
-    {
-      g_free (private->values);
-      g_free (private->resolutions);
-      private->num_values = 0;
-    }
+  g_clear_pointer (&private->values,      g_free);
+  g_clear_pointer (&private->resolutions, g_free);
+  private->num_values = 0;
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }


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