From 2da5e5ee5568145884eebbeb1a012559466a644b Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sat, 12 May 2018 10:40:15 +0200 Subject: [PATCH] [TextBox] Add a reference to the cairo surface when displaying an icon. --- source/widgets/textbox.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c index 5f588bd9..04dfc7d2 100644 --- a/source/widgets/textbox.c +++ b/source/widgets/textbox.c @@ -334,6 +334,14 @@ void textbox_text ( textbox *tb, const char *text ) void textbox_icon ( textbox *tb, cairo_surface_t *icon ) { + // Add our reference to the surface. + if ( icon != NULL ) { + cairo_surface_reference ( icon ); + } + if ( tb->icon ) { + // If we overwrite an old one, destroy the reference we hold. + cairo_surface_destroy ( tb->icon ); + } tb->icon = icon; widget_queue_redraw ( WIDGET ( tb ) ); @@ -390,6 +398,10 @@ static void textbox_free ( widget *wid ) } g_free ( tb->text ); + if ( tb->icon ) { + cairo_surface_destroy ( tb->icon ); + tb->icon = NULL; + } if ( tb->layout != NULL ) { g_object_unref ( tb->layout ); }