Is font face reference counting broken?

Andreas Falkenhahn andreas at falkenhahn.com
Wed May 15 13:27:29 UTC 2024


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 --------------
A non-text attachment was scrubbed...
Name: test.c
Type: application/octet-stream
Size: 1365 bytes
Desc: not available
URL: <https://lists.cairographics.org/archives/cairo/attachments/20240515/1e1f1b0f/attachment.obj>


More information about the cairo mailing list