[gegl] buffer: stop leaking buffers whenever gegl_buffer_sample is called



commit b0257438c1542a42be6a550a54c9677e8f59ead9
Author: Michael Henning <drawoc darkrefraction com>
Date:   Sun Apr 7 12:11:27 2013 -0400

    buffer: stop leaking buffers whenever gegl_buffer_sample is called

 gegl/buffer/gegl-buffer-access.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-access.c b/gegl/buffer/gegl-buffer-access.c
index a690a6a..c486df7 100644
--- a/gegl/buffer/gegl-buffer-access.c
+++ b/gegl/buffer/gegl-buffer-access.c
@@ -1647,8 +1647,7 @@ gegl_buffer_sample (GeglBuffer       *buffer,
        buffer->sampler_format != format
       ))
     {
-      g_object_unref (buffer->sampler);
-      buffer->sampler = NULL;
+      gegl_buffer_sample_cleanup (buffer);
     }
 
   /* look up appropriate sampler,. */
@@ -1660,6 +1659,14 @@ gegl_buffer_sample (GeglBuffer       *buffer,
                                       NULL);
       buffer->sampler_format = format;
       gegl_sampler_prepare (buffer->sampler);
+
+      /*
+       * Hack: the sampler refs the buffer on creation. We therefore unref
+       * the buffer here so it isn't leaked. Then, before the sampler is
+       * freed in gegl_buffer_sample_cleanup, we ref the buffer again so
+       * it isn't accidentally freed by the sampler
+       */
+      g_object_unref (buffer);
     }
 
   gegl_sampler_get (buffer->sampler, x, y, scale, dest, repeat_mode);
@@ -1672,6 +1679,9 @@ gegl_buffer_sample_cleanup (GeglBuffer *buffer)
 
   if (buffer->sampler)
     {
+      /* Hack (see above) */
+      g_object_ref (buffer);
+
       g_object_unref (buffer->sampler);
       buffer->sampler = NULL;
     }


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