[gegl] buffer: stop leaking the buffer pool in gegl-buffer-iterator.



commit 7a74a26ec74685fdd50b6e9fe0d284db76d96e08
Author: Michael Henning <drawoc darkrefraction com>
Date:   Wed Apr 3 17:07:35 2013 -0400

    buffer: stop leaking the buffer pool in gegl-buffer-iterator.

 gegl/buffer/gegl-buffer-iterator-private.h |   24 ++++++++++++++++++++++++
 gegl/buffer/gegl-buffer-iterator.c         |   22 ++++++++++++++++++----
 gegl/gegl-init.c                           |    2 ++
 3 files changed, 44 insertions(+), 4 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-iterator-private.h b/gegl/buffer/gegl-buffer-iterator-private.h
new file mode 100644
index 0000000..fba012b
--- /dev/null
+++ b/gegl/buffer/gegl-buffer-iterator-private.h
@@ -0,0 +1,24 @@
+/* This file is part of GEGL.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2013 Michael Henning <drawoc darkrefraction com>
+ */
+
+#ifndef __GEGL_BUFFER_ITERATOR_PRIVATE_H__
+#define __GEGL_BUFFER_ITERATOR_PRIVATE_H__
+
+void _gegl_buffer_iterator_cleanup (void);
+
+#endif
diff --git a/gegl/buffer/gegl-buffer-iterator.c b/gegl/buffer/gegl-buffer-iterator.c
index e4b7933..e200087 100644
--- a/gegl/buffer/gegl-buffer-iterator.c
+++ b/gegl/buffer/gegl-buffer-iterator.c
@@ -322,10 +322,6 @@ gegl_buffer_iterator_add (GeglBufferIterator  *iterator,
   return self;
 }
 
-/* FIXME: we are currently leaking this buf pool, it should be
- * freed when gegl is uninitialized
- */
-
 typedef struct BufInfo {
   gint     size;
   gint     used;  /* if this buffer is currently allocated */
@@ -382,6 +378,24 @@ static void iterator_buf_pool_release (gpointer buf)
   g_mutex_unlock (&pool_mutex);
 }
 
+void
+_gegl_buffer_iterator_cleanup ()
+{
+  gint i;
+  /* FIXME: is the mutex lock necessary? */
+  g_mutex_lock (&pool_mutex);
+  if (buf_pool) {
+    for (i=0; i<buf_pool->len; i++)
+      {
+        BufInfo *info = &g_array_index (buf_pool, BufInfo, i);
+        gegl_free (info->buf);
+      }
+    g_array_free (buf_pool, TRUE);
+    buf_pool = NULL;
+  }
+  g_mutex_unlock (&pool_mutex);
+}
+
 static void ensure_buf (GeglBufferIterators *i, gint no)
 {
   if (i->buf[no]==NULL)
diff --git a/gegl/gegl-init.c b/gegl/gegl-init.c
index 1aab900..4920643 100644
--- a/gegl/gegl-init.c
+++ b/gegl/gegl-init.c
@@ -92,6 +92,7 @@ guint gegl_debug_flags = 0;
 #include "operation/gegl-operations.h"
 #include "operation/gegl-extension-handler.h"
 #include "buffer/gegl-buffer-private.h"
+#include "buffer/gegl-buffer-iterator-private.h"
 #include "buffer/gegl-tile-backend-ram.h"
 #include "buffer/gegl-tile-backend-tiledir.h"
 #include "buffer/gegl-tile-backend-file.h"
@@ -397,6 +398,7 @@ gegl_exit (void)
   gegl_tile_cache_destroy ();
   gegl_operation_gtype_cleanup ();
   gegl_extension_handler_cleanup ();
+  _gegl_buffer_iterator_cleanup ();
 
   if (module_db != NULL)
     {


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