[gtk/matthiasc/for-master: 3/3] text: Be more careful with cached layouts



commit 17a9b13af2c30e00fcf88da746691cc810594644
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Apr 12 15:12:37 2020 -0400

    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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]