[cairo] cairo_font_face_t not freeing

Louis M prog at tioui.com
Wed May 3 00:46:53 UTC 2017


On 05/02/2017 04:31 PM, Lawrence D'Oliveiro wrote:
> So presumably Cairo knows to clean it up
> properly when you call font_face_destroy...
Ok, just to be sure, I tried the the "cairo_font_face_set_user_data"
functionality that can set a destructor to the font face. Here the code:

void font_destroy(void* user_data){
    printf("Font face freed\n");
}

int main(void){
    static const cairo_user_data_key_t key;
    int temp;
    cairo_scaled_font_t * scaled_font;

    // Creating ressources
    cairo_font_face_t * font_face = cairo_toy_font_face_create("",
                            CAIRO_FONT_SLANT_NORMAL,
                            CAIRO_FONT_WEIGHT_NORMAL);
    cairo_font_face_set_user_data (font_face, &key,
                &temp, (cairo_destroy_func_t) font_destroy);
    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_destroy(context);
    cairo_surface_destroy(surface);
    printf("Refcount=%d\n", cairo_font_face_get_reference_count(font_face));
    cairo_font_face_destroy(font_face);

    return 0;
}

The "font_destroy" is never launch. But if I put two
"cairo_font_face_destroy" instead of one, I see the "Font face freed"
message. Do you think that I should fill a bug report. It do not seems
to be a misuse from my part if a understand correctly.

Thanks again,

Louis M



More information about the cairo mailing list