Is font face reference counting broken?

Behdad Esfahbod behdad at behdad.org
Wed May 15 14:13:12 UTC 2024


the font cache of cairo holds onto the face.

behdad
http://behdad.org/


On Wed, May 15, 2024 at 8:00 AM Andreas Falkenhahn <andreas at falkenhahn.com>
wrote:

> I've noticed that the font face reference counting behaves a little weird
> in Cairo. Take a look at this code:
>
>         printf("REF COUNT A: %d\n",
> cairo_font_face_get_reference_count(fface));
>
>         cairo_set_font_face(cr, fface);
>
>         printf("REF COUNT B: %d\n",
> cairo_font_face_get_reference_count(fface));
>
>         cairo_set_font_size(cr, 36);
>         cairo_show_glyphs(cr, g, 1);
>
>         printf("REF COUNT C: %d\n",
> cairo_font_face_get_reference_count(fface));
>
>         cairo_destroy(cr);
>         cairo_surface_destroy(surf);
>
>         printf("REF COUNT D: %d\n",
> cairo_font_face_get_reference_count(fface));
>
>         cairo_font_face_destroy(fface);
>
>         printf("REF COUNT E: %d\n",
> cairo_font_face_get_reference_count(fface));
>
> This prints the following here:
>
>        REF COUNT A: 1
>        REF COUNT B: 2
>        REF COUNT C: 4
>        REF COUNT D: 3
>        REF COUNT E: 2
>
> The values for ref count A, B, C are look correct AFAICS but what about
> the ref count value D? As you can see, I get 3 for ref count D but
> shouldn't this be back to 1 at this stage?
>
> Consequently, since ref count value D is still 3, the ensuing call to
> cairo_font_face_destroy() won't actually destroy the font face but just
> decrease its ref count to 2 but isn't this wrong?
>
> To me it looks like either cairo_destroy() or cairo_show_glyphs() don't
> unref the font face correctly. I'd expect that after cairo_destroy()
> returns the ref count should be back to 1, shouldn't it?
>
> Or am I doing/understanding something wrong here?
>
> I'm attaching the full little demo program.
>
> --
> Best regards,
>  Andreas Falkenhahn                          mailto:andreas at falkenhahn.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cairographics.org/archives/cairo/attachments/20240515/c1b8c2cc/attachment.htm>


More information about the cairo mailing list