Thread safety problem in pango_font_get_hb_font_for_context
Static variable funcs
can be accessed by multiple threads without proper synchronization (UB):
https://gitlab.gnome.org/GNOME/pango/-/blob/main/pango/shape.c#L239-253
This causes for example this leak reported by leak sanitizer:
Direct leak of 424 byte(s) in 1 object(s) allocated from:
#1 0x7f319bd3a716 in hb_object_create<hb_font_funcs_t> build-main/src/../../src/hb-object.hh:227:31
#2 0x7f319bd3a716 in hb_font_funcs_create build-main/src/../../src/hb-font.cc:532:52
Possible solution could be to use g_once_init_enter
like this:
if (G_UNLIKELY (g_once_init_enter(&funcs)))
{
hb_font_funcs_t *f = hb_font_funcs_create ();
hb_font_funcs_set_nominal_glyph_func (f, pango_hb_font_get_nominal_glyph, NULL, NULL);
hb_font_funcs_set_glyph_h_advance_func (f, pango_hb_font_get_glyph_h_advance, NULL, NULL);
hb_font_funcs_set_glyph_v_advance_func (f, pango_hb_font_get_glyph_v_advance, NULL, NULL);
hb_font_funcs_set_glyph_extents_func (f, pango_hb_font_get_glyph_extents, NULL, NULL);
hb_font_funcs_make_immutable (f);
g_once_init_leave(&funcs, f);
}