[cairo] [PATCH] Fix a 'memory leak' in the image compositor

Uli Schlachter psychon at znc.in
Sat Jan 13 13:49:52 UTC 2018


There is a global pixman_glyph_cache_t instance that is initialized on
first use and shows up in valgrind output as a relatively large leak (I
think it was about 200 KiB). The reason for this is that this cache is
not freed by cairo_debug_reset_static_data().

This commit wires up freeing the cache to
cairo_debug_reset_static_data().

This cache was introduced in commit 615205cf0729 from 2012.

Signed-off-by: Uli Schlachter <psychon at znc.in>
---
 src/cairo-debug.c            |  2 ++
 src/cairo-image-compositor.c | 17 +++++++++++++++++
 src/cairoint.h               |  3 +++
 3 files changed, 22 insertions(+)

diff --git a/src/cairo-debug.c b/src/cairo-debug.c
index 10933a673..6005060d4 100644
--- a/src/cairo-debug.c
+++ b/src/cairo-debug.c
@@ -86,6 +86,8 @@ cairo_debug_reset_static_data (void)
 
     _cairo_image_reset_static_data ();
 
+    _cairo_image_compositor_reset_static_data ();
+
 #if CAIRO_HAS_DRM_SURFACE
     _cairo_drm_device_reset_static_data ();
 #endif
diff --git a/src/cairo-image-compositor.c b/src/cairo-image-compositor.c
index 9f4e0adad..122a8ca42 100644
--- a/src/cairo-image-compositor.c
+++ b/src/cairo-image-compositor.c
@@ -820,6 +820,18 @@ get_glyph_cache (void)
     return global_glyph_cache;
 }
 
+void
+_cairo_image_compositor_reset_static_data (void)
+{
+    CAIRO_MUTEX_LOCK (_cairo_glyph_cache_mutex);
+
+    if (global_glyph_cache)
+	pixman_glyph_cache_destroy (global_glyph_cache);
+    global_glyph_cache = NULL;
+
+    CAIRO_MUTEX_UNLOCK (_cairo_glyph_cache_mutex);
+}
+
 void
 _cairo_image_scaled_glyph_fini (cairo_scaled_font_t *scaled_font,
 				cairo_scaled_glyph_t *scaled_glyph)
@@ -945,6 +957,11 @@ out_unlock:
     return status;
 }
 #else
+void
+_cairo_image_compositor_reset_static_data (void)
+{
+}
+
 void
 _cairo_image_scaled_glyph_fini (cairo_scaled_font_t *scaled_font,
 				cairo_scaled_glyph_t *scaled_glyph)
diff --git a/src/cairoint.h b/src/cairoint.h
index 051e4f805..11f2c1eaf 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -1586,6 +1586,9 @@ _cairo_image_scaled_glyph_fini (cairo_scaled_font_t *scaled_font,
 cairo_private void
 _cairo_image_reset_static_data (void);
 
+cairo_private void
+_cairo_image_compositor_reset_static_data (void);
+
 cairo_private cairo_surface_t *
 _cairo_image_surface_create_with_pixman_format (unsigned char		*data,
 						pixman_format_code_t	 pixman_format,
-- 
2.15.1



More information about the cairo mailing list