[gimp] Bug 765492: Memory leak in gimp_brush_cache_add
- From: Massimo Valentini <mvalentini src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] Bug 765492: Memory leak in gimp_brush_cache_add
- Date: Sun, 24 Apr 2016 17:42:42 +0000 (UTC)
commit 022439e4633083df7533de767e48e854fcf23282
Author: Massimo Valentini <mvalentini src gnome org>
Date: Sun Apr 24 19:41:22 2016 +0200
Bug 765492: Memory leak in gimp_brush_cache_add
g_free the lru 'unit' when removed from the cache
and keep track of the list length and last item
while looking for a duplicate already present in
the cache.
app/core/gimpbrushcache.c | 13 +++++++++----
1 files changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/app/core/gimpbrushcache.c b/app/core/gimpbrushcache.c
index 99aab4d..45ad497 100644
--- a/app/core/gimpbrushcache.c
+++ b/app/core/gimpbrushcache.c
@@ -258,6 +258,8 @@ gimp_brush_cache_add (GimpBrushCache *cache,
{
GList *iter;
GimpBrushCacheUnit *unit;
+ GList *last = NULL;
+ gint length = 0;
g_return_if_fail (GIMP_IS_BRUSH_CACHE (cache));
g_return_if_fail (data != NULL);
@@ -268,15 +270,18 @@ gimp_brush_cache_add (GimpBrushCache *cache,
if (data == unit->data)
return;
+
+ length++;
+ last = iter;
}
- if (g_list_length (cache->cached_units) > MAX_CACHED_DATA &&
- (iter = g_list_last (cache->cached_units)))
+ if (length > MAX_CACHED_DATA)
{
- unit = iter->data;
+ unit = last->data;
cache->data_destroy (unit->data);
- cache->cached_units = g_list_delete_link (cache->cached_units, iter);
+ cache->cached_units = g_list_delete_link (cache->cached_units, last);
+ g_free (unit);
}
unit = g_new0 (GimpBrushCacheUnit, 1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]