From 17a9b13af2c30e00fcf88da746691cc810594644 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 12 Apr 2020 15:12:37 -0400 Subject: [PATCH] text: Be more careful with cached layouts If we call any functions that may call ensure_layout themeselves, we risk having the cached layout pulled out from underneath. Better play it safe and take a reference. --- gtk/gtktext.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gtk/gtktext.c b/gtk/gtktext.c index a80a78b616..311a3e7246 100644 --- a/gtk/gtktext.c +++ b/gtk/gtktext.c @@ -4564,7 +4564,7 @@ gtk_text_draw_cursor (GtkText *self, context = gtk_widget_get_style_context (widget); - layout = gtk_text_ensure_layout (self, TRUE); + layout = g_object_ref (gtk_text_ensure_layout (self, TRUE)); text = pango_layout_get_text (layout); gtk_text_get_layout_offsets (self, &x, &y); @@ -4604,6 +4604,8 @@ gtk_text_draw_cursor (GtkText *self, gtk_style_context_restore (context); } + + g_object_unref (layout); } static void