[gegl/gsoc2009-gpu] GeglBufferIterator: Implement proper buffer pool finalization
- From: Jerson Michael Perpetua <jperpetua src gnome org>
- To: svn-commits-list gnome org
- Subject: [gegl/gsoc2009-gpu] GeglBufferIterator: Implement proper buffer pool finalization
- Date: Tue, 7 Jul 2009 17:47:39 +0000 (UTC)
commit a5d2c4274ca9641d20b9086125d072c9e5c6a18a
Author: Jerson Michael Perpetua <jersonperpetua gmail com>
Date: Mon Jul 6 02:21:01 2009 +0800
GeglBufferIterator: Implement proper buffer pool finalization
Add gegl_buffer_iterator_cleanup() and call it in gegl_exit(). This
should fix the memory leak caused by the iterator buf pool.
gegl/buffer/gegl-buffer-iterator.c | 23 ++++++++++++++++++-----
gegl/buffer/gegl-buffer-iterator.h | 23 ++++++++++++-----------
gegl/gegl-init.c | 2 ++
3 files changed, 32 insertions(+), 16 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-iterator.c b/gegl/buffer/gegl-buffer-iterator.c
index d220194..1d1d550 100644
--- a/gegl/buffer/gegl-buffer-iterator.c
+++ b/gegl/buffer/gegl-buffer-iterator.c
@@ -317,10 +317,6 @@ gegl_buffer_iterator_add (GeglBufferIterator *iterator,
return self;
}
-/* FIXME: we are currently leaking this buf pool, it should be
- * freeing it when gegl is uninitialized
- */
-
/* XXX: keeping a small pool of such buffers around for the used formats
* would probably improve performance (old note from pippin, kept as a
* reminder)
@@ -377,8 +373,22 @@ iterator_buf_pool_release (gpointer buf)
return;
}
}
+}
+
+void
+gegl_buffer_iterator_cleanup (void)
+{
+ gint cnt;
+
+ for (cnt = 0; cnt < buf_pool->len; cnt++)
+ {
+ BufInfo *info = &g_array_index (buf_pool, BufInfo, cnt);
+ gegl_free (info->buf);
+ info->buf = NULL;
+ }
- g_assert (0);
+ g_array_free (buf_pool, TRUE);
+ buf_pool = NULL;
}
#if DEBUG_DIRECT
@@ -430,6 +440,9 @@ gegl_buffer_iterator_next (GeglBufferIterator *iterator)
GEGL_AUTO_ROWSTRIDE);
}
+ /* XXX: might be inefficient given the current implementation,
+ * should be easy to reimplement the pool as a hash table
+ */
iterator_buf_pool_release (i->data[no]);
}
diff --git a/gegl/buffer/gegl-buffer-iterator.h b/gegl/buffer/gegl-buffer-iterator.h
index 53268c3..0d0b6f5 100644
--- a/gegl/buffer/gegl-buffer-iterator.h
+++ b/gegl/buffer/gegl-buffer-iterator.h
@@ -62,12 +62,12 @@ typedef struct GeglBufferIterator
* Returns: a new buffer iterator that can be used to iterate through the
* buffers pixels.
*/
-GeglBufferIterator *gegl_buffer_iterator_new (GeglBuffer *buffer,
- const GeglRectangle *roi,
- const Babl *format,
- guint flags);
+GeglBufferIterator *gegl_buffer_iterator_new (GeglBuffer *buffer,
+ const GeglRectangle *roi,
+ const Babl *format,
+ guint flags);
-void gegl_buffer_iterator_free (GeglBufferIterator *iterator);
+void gegl_buffer_iterator_free (GeglBufferIterator *i);
/**
* gegl_buffer_iterator_add:
@@ -85,11 +85,11 @@ void gegl_buffer_iterator_free (GeglBufferIterator *iterator);
* Returns: an integer handle refering to the index in the iterator structure
* of the added buffer.
*/
-gint gegl_buffer_iterator_add (GeglBufferIterator *iterator,
- GeglBuffer *buffer,
- const GeglRectangle *roi,
- const Babl *format,
- guint flags);
+gint gegl_buffer_iterator_add (GeglBufferIterator *iterator,
+ GeglBuffer *buffer,
+ const GeglRectangle *roi,
+ const Babl *format,
+ guint flags);
/**
* gegl_buffer_iterator_next:
@@ -103,8 +103,9 @@ gint gegl_buffer_iterator_add (GeglBufferIterator *iterator,
*
* Returns: TRUE if there is more work FALSE if iteration is complete.
*/
-gboolean gegl_buffer_iterator_next (GeglBufferIterator *iterator);
+gboolean gegl_buffer_iterator_next (GeglBufferIterator *iterator);
+void gegl_buffer_iterator_cleanup (void);
#ifdef EXAMPLE
GeglBufferIterator *gi = gegl_buffer_iterator_new (buffer,
diff --git a/gegl/gegl-init.c b/gegl/gegl-init.c
index 89542bf..5352439 100644
--- a/gegl/gegl-init.c
+++ b/gegl/gegl-init.c
@@ -397,6 +397,8 @@ gegl_exit (void)
config = NULL;
g_printf ("\n");
+
+ gegl_buffer_iterator_cleanup ();
}
static void swap_clean (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]