[gegl] Clean up the way we drop references and free memory



commit 6ff68497cc2e0cb05fabe6560277e099d63d9ccc
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Feb 3 03:29:25 2017 +0100

    Clean up the way we drop references and free memory

 bin/ui.c                                     |    6 +-----
 gegl/operation/gegl-operation-filter.c       |    4 +---
 gegl/operation/gegl-operation-point-filter.c |    4 +---
 operations/external/jp2-load.c               |    8 ++------
 operations/external/raw-load.c               |   13 +++----------
 operations/external/svg-load.c               |    7 ++-----
 operations/external/tiff-load.c              |    7 +++----
 operations/external/tiff-save.c              |    7 +++----
 operations/external/webp-load.c              |   16 ++++++----------
 9 files changed, 22 insertions(+), 50 deletions(-)
---
diff --git a/bin/ui.c b/bin/ui.c
index 1eb0c69..0bb27f1 100644
--- a/bin/ui.c
+++ b/bin/ui.c
@@ -371,11 +371,7 @@ int mrg_ui_main (int argc, char **argv, char **ops)
   mrg_main (mrg);
 
   g_object_unref (o.gegl);
-  if (o.buffer)
-  {
-    g_object_unref (o.buffer);
-    o.buffer = NULL;
-  }
+  g_clear_object (&o.buffer);
   gegl_exit ();
 
   end_audio ();
diff --git a/gegl/operation/gegl-operation-filter.c b/gegl/operation/gegl-operation-filter.c
index aaaae40..ee96382 100644
--- a/gegl/operation/gegl-operation-filter.c
+++ b/gegl/operation/gegl-operation-filter.c
@@ -220,9 +220,7 @@ gegl_operation_filter_process (GeglOperation        *operation,
     success = klass->process (operation, input, output, result, level);
   }
 
-  if (input != NULL)
-    g_object_unref (input);
-
+  g_clear_object (&input);
   return success;
 }
 
diff --git a/gegl/operation/gegl-operation-point-filter.c b/gegl/operation/gegl-operation-point-filter.c
index 03a38d2..8c76aa4 100644
--- a/gegl/operation/gegl-operation-point-filter.c
+++ b/gegl/operation/gegl-operation-point-filter.c
@@ -124,9 +124,7 @@ gegl_operation_filter_process (GeglOperation        *operation,
   if (input != NULL)
     {
       success = klass->process (operation, input, output, result, level);
-
-      if (input)
-        g_object_unref (input);
+      g_clear_object (&input);
     }
   else
     {
diff --git a/operations/external/jp2-load.c b/operations/external/jp2-load.c
index dad2982..eb2b5a6 100644
--- a/operations/external/jp2-load.c
+++ b/operations/external/jp2-load.c
@@ -57,12 +57,8 @@ cleanup(GeglOperation *operation)
 
   if (p != NULL)
     {
-      if (p->image != NULL)
-        jas_image_destroy(p->image);
-      p->image = NULL;
-
-      if (p->file != NULL)
-        g_clear_object(&p->file);
+      g_clear_pointer (&p->image, (GDestroyNotify) jas_image_destroy);
+      g_clear_object (&p->file);
 
       p->width = p->height = 0;
       p->format = NULL;
diff --git a/operations/external/raw-load.c b/operations/external/raw-load.c
index ecf0859..b1f06b1 100644
--- a/operations/external/raw-load.c
+++ b/operations/external/raw-load.c
@@ -65,16 +65,9 @@ static void
 raw_close (GeglProperties *o)
 {
   Private *p = (Private*)o->user_data;
-  if (p->LibRaw != NULL)
-    {
-      if (p->image != NULL)
-      {
-        libraw_dcraw_clear_mem (p->image);
-        p->image = NULL;
-      }
-      libraw_close (p->LibRaw);
-      p->LibRaw = NULL;
-    }
+
+  g_clear_pointer (&p->image, (GDestroyNotify) libraw_dcraw_clear_mem);
+  g_clear_pointer (&p->LibRaw, (GDestroyNotify) libraw_close);
 }
 
 static void
diff --git a/operations/external/svg-load.c b/operations/external/svg-load.c
index c4db062..cce7c54 100644
--- a/operations/external/svg-load.c
+++ b/operations/external/svg-load.c
@@ -63,11 +63,8 @@ cleanup (GeglOperation *operation)
 
   if (p != NULL)
     {
-      if (p->handle != NULL)
-        g_clear_object (&p->handle);
-
-      if (p->file != NULL)
-        g_clear_object(&p->file);
+      g_clear_object (&p->handle);
+      g_clear_object (&p->file);
 
       p->width = p->height = 0;
       p->format = NULL;
diff --git a/operations/external/tiff-load.c b/operations/external/tiff-load.c
index af15309..ff2a1c5 100644
--- a/operations/external/tiff-load.c
+++ b/operations/external/tiff-load.c
@@ -83,12 +83,11 @@ cleanup(GeglOperation *operation)
         TIFFClose(p->tiff);
       else if (p->stream != NULL)
         g_input_stream_close(G_INPUT_STREAM(p->stream), NULL, NULL);
-      if (p->stream != NULL)
-        g_clear_object(&p->stream);
+
+      g_clear_object (&p->stream);
       p->tiff = NULL;
 
-      if (p->file != NULL)
-        g_clear_object(&p->file);
+      g_clear_object (&p->file);
 
       p->width = p->height = 0;
       p->directory = 0;
diff --git a/operations/external/tiff-save.c b/operations/external/tiff-save.c
index 8e012b8..7f9923a 100644
--- a/operations/external/tiff-save.c
+++ b/operations/external/tiff-save.c
@@ -61,12 +61,11 @@ cleanup(GeglOperation *operation)
         TIFFClose(p->tiff);
       else if (p->stream != NULL)
         g_output_stream_close(G_OUTPUT_STREAM(p->stream), NULL, NULL);
-      if (p->stream != NULL)
-        g_clear_object(&p->stream);
+
+      g_clear_object (&p->stream);
       p->tiff = NULL;
 
-      if (p->file != NULL)
-        g_clear_object(&p->file);
+      g_clear_object (&p->file);
     }
 }
 
diff --git a/operations/external/webp-load.c b/operations/external/webp-load.c
index 9075868..c525536 100644
--- a/operations/external/webp-load.c
+++ b/operations/external/webp-load.c
@@ -61,22 +61,18 @@ cleanup(GeglOperation *operation)
 
   if (p != NULL)
     {
-      if (p->decoder != NULL)
-        WebPIDelete (p->decoder);
-      p->decoder = NULL;
+      g_clear_pointer (&p->decoder, (GDestroyNotify) WebPIDelete);
+
       if (p->config != NULL)
         WebPFreeDecBuffer (&p->config->output);
-      if (p->config != NULL)
-        g_free (p->config);
-      p->config = NULL;
+
+      g_clear_pointer (&p->config, g_free);
 
       if (p->stream != NULL)
         g_input_stream_close (G_INPUT_STREAM (p->stream), NULL, NULL);
-      if (p->stream != NULL)
-        g_clear_object (&p->stream);
 
-      if (p->file != NULL)
-        g_clear_object (&p->file);
+      g_clear_object (&p->stream);
+      g_clear_object (&p->file);
 
       p->width = p->height = 0;
       p->format = NULL;


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