From ec4b95db16a8728b4c972bf4045a286b7f041498 Mon Sep 17 00:00:00 2001 From: rbuj Date: Fri, 28 Jan 2022 11:26:20 +0100 Subject: matekbd-keyboard-drawing: fix memory leak --- libmatekbd/matekbd-keyboard-drawing.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/libmatekbd/matekbd-keyboard-drawing.c b/libmatekbd/matekbd-keyboard-drawing.c index 053eded..8b99f85 100644 --- a/libmatekbd/matekbd-keyboard-drawing.c +++ b/libmatekbd/matekbd-keyboard-drawing.c @@ -1623,16 +1623,15 @@ alloc_render_context (MatekbdKeyboardDrawing * drawing) GtkStyleContext *style_context = gtk_widget_get_style_context (GTK_WIDGET (drawing)); - PangoFontDescription *fd = NULL; gtk_style_context_get (style_context, gtk_style_context_get_state (style_context), - GTK_STYLE_PROPERTY_FONT, &fd, NULL); + GTK_STYLE_PROPERTY_FONT, &context->font_desc, + NULL); context->layout = pango_layout_new (pangoContext); pango_layout_set_ellipsize (context->layout, PANGO_ELLIPSIZE_END); - context->font_desc = pango_font_description_copy (fd); context->angle = 0; context->scale_numerator = 1; context->scale_denominator = 1; @@ -2439,7 +2438,7 @@ matekbd_keyboard_drawing_render (MatekbdKeyboardDrawing * kbdrawing, GtkStyleContext *style_context = gtk_widget_get_style_context (GTK_WIDGET (kbdrawing)); GdkRGBA dark_color; - PangoFontDescription *fd = NULL; + PangoFontDescription *fd; gtk_style_context_get_background_color (style_context, gtk_style_context_get_state (style_context), @@ -2451,21 +2450,25 @@ matekbd_keyboard_drawing_render (MatekbdKeyboardDrawing * kbdrawing, gtk_style_context_get (style_context, gtk_style_context_get_state (style_context), - GTK_STYLE_PROPERTY_FONT, &fd, NULL); - fd = pango_font_description_copy (fd); + GTK_STYLE_PROPERTY_FONT, &fd, + NULL); MatekbdKeyboardDrawingRenderContext context = { cr, kbdrawing->renderContext->angle, layout, - pango_font_description_copy (fd), + fd, 1, 1, dark_color }; if (!context_setup_scaling (&context, kbdrawing, width, height, dpi_x, dpi_y)) + { + pango_font_description_free (fd); return FALSE; + } + cairo_translate (cr, x, y); draw_keyboard_to_context (&context, kbdrawing); -- cgit v1.2.1