[cairo] cairo_font_face_t not freeing

Louis M prog at tioui.com
Tue May 2 01:11:02 UTC 2017


Hello everyone,

I am new to Cairo and I have a problem with the freeing of a
cairo_font_face_t object. I write a little code to show you the problem:

#include <stdio.h>
#include <cairo.h>
#include <cairo-pdf.h>

int main(void){
    cairo_scaled_font_t * scaled_font;
    int num_glyphs;
    int num_clusters;
    cairo_text_cluster_flags_t cluster_flags;
    cairo_glyph_t * glyph = NULL;
    cairo_text_cluster_t *clusters = NULL;

    // Creating ressources
    cairo_font_face_t * font_face = cairo_toy_font_face_create("",
                            CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);
    cairo_surface_t * surface = cairo_pdf_surface_create("test.pdf",
300, 300);
    cairo_t * context = cairo_create(surface);
    cairo_set_font_face(context, font_face);
    cairo_set_font_size(context, 30);
    scaled_font = cairo_get_scaled_font(context);

    // Freeing ressources
    cairo_glyph_free(glyph);
    cairo_text_cluster_free (clusters);
    cairo_destroy(context);
    cairo_surface_destroy(surface);
    cairo_font_face_destroy(font_face);
    printf("Refcount=%d\n", cairo_font_face_get_reference_count(font_face));

    return 0;
}

The problem is: I don't know what I didn't freed, but at the end (in the
'printf'), I get a reference count of 'font_face' of 1. Just to be sure
that it is not memory garbage after the 'cairo_font_face_destroy' where
the 'font_face' could be not valid anymore, I tried to put the same
'printf' before the line with the 'cairo_font_face_destroy' and I got 2.
So, I'm probably missing something, but I don't know what. I don't want
to actually adding another 'cairo_font_face_destroy' without actually
knowing why I need it. Can somebody help me.

Thanks,

Louis M




More information about the cairo mailing list