cairo-util: Clean up more Cairo detritus; almost all of it

Pango, Cairo, and fontconfig, all want to leave thread-global data
hanging around in order to maintain a cache. Try to clean up as much of
it as we possibly can on exit, apart from the Pango language string
which appears to be unfreeable, so has been added to LSan suppressions.

Signed-off-by: Daniel Stone <daniels@collabora.com>
This commit is contained in:
Daniel Stone 2022-06-24 12:47:47 +01:00
parent 29c3422e05
commit c55a14206d
5 changed files with 25 additions and 2 deletions

View file

@ -3,3 +3,6 @@
# Cairo internal leaks from weston-keyboard
leak:cairo_select_font_face
leak:cairo_text_extents
# Pango thread-global state (not destroyable?)
leak:pango_language_get_default

View file

@ -6063,6 +6063,7 @@ display_destroy(struct display *display)
theme_destroy(display->theme);
destroy_cursors(display);
cleanup_after_cairo();
if (display->relative_pointer_manager)
zwp_relative_pointer_manager_v1_destroy(display->relative_pointer_manager);

View file

@ -40,6 +40,7 @@
#include <libweston/config-parser.h>
#ifdef HAVE_PANGO
#include <fontconfig/fontconfig.h>
#include <pango/pangocairo.h>
#endif
@ -681,3 +682,17 @@ theme_get_location(struct theme *t, int x, int y,
return location;
}
/** Cleanup static Cairo/Pango data
*
* Using Cairo, Pango, PangoCairo, and fontconfig, ends up leaving a trail of
* thread-cached data behind us. Clean up what we can.
*/
void
cleanup_after_cairo(void)
{
cairo_debug_reset_static_data();
#ifdef HAVE_PANGO
FcFini();
#endif
}

View file

@ -234,4 +234,7 @@ frame_double_touch_up(struct frame *frame, void *data, int32_t id);
void
frame_repaint(struct frame *frame, cairo_t *cr);
void
cleanup_after_cairo(void);
#endif

View file

@ -57,10 +57,11 @@ deps_cairo_shared = [
dep_pango = dependency('pango', required: false)
dep_pangocairo = dependency('pangocairo', required: false)
dep_fontconfig = dependency('fontconfig', required: false)
dep_glib = dependency('glib-2.0', version: '>= 2.36', required: false)
if dep_pango.found() and dep_pangocairo.found() and dep_glib.found()
deps_cairo_shared += [ dep_pango, dep_pangocairo, dep_glib ]
if dep_pango.found() and dep_pangocairo.found() and dep_fontconfig.found() and dep_glib.found()
deps_cairo_shared += [ dep_pango, dep_pangocairo, dep_fontconfig, dep_glib ]
config_h.set('HAVE_PANGO', '1')
endif