[gtk/wip/otte/for-master: 1/3] demo: Don't crash when closing words demo




commit 278fbcbbb4bff06b7e8e4ea0d3700b8a725bba51
Author: Benjamin Otte <otte redhat com>
Date:   Fri Aug 7 02:49:41 2020 +0200

    demo: Don't crash when closing words demo
    
    Make sure the stringlist we're loading into doesn't go away.
    
    It'd be better to have a cancellable, but I'm lazy.

 demos/gtk-demo/listview_words.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
---
diff --git a/demos/gtk-demo/listview_words.c b/demos/gtk-demo/listview_words.c
index 50e40adc20..350383a4da 100644
--- a/demos/gtk-demo/listview_words.c
+++ b/demos/gtk-demo/listview_words.c
@@ -65,6 +65,7 @@ read_lines_cb (GObject      *object,
     {
       g_print ("Could not read data: %s\n", error->message);
       g_clear_error (&error);
+      g_object_unref (stringlist);
       return;
     }
 
@@ -74,6 +75,7 @@ read_lines_cb (GObject      *object,
     {
       if (size)
         gtk_string_list_take (stringlist, g_utf8_make_valid (buffer, size));
+      g_object_unref (stringlist);
       return;
     }
 
@@ -121,6 +123,7 @@ file_is_open_cb (GObject      *file,
     {
       g_print ("Could not open file: %s\n", error->message);
       g_error_free (error);
+      g_object_unref (data);
       return;
     }
 
@@ -134,7 +137,7 @@ load_file (GtkStringList *list,
            GFile         *file)
 {
   gtk_string_list_splice (list, 0, g_list_model_get_n_items (G_LIST_MODEL (list)), NULL);
-  g_file_read_async (file, G_PRIORITY_HIGH_IDLE, NULL, file_is_open_cb, list);
+  g_file_read_async (file, G_PRIORITY_HIGH_IDLE, NULL, file_is_open_cb, g_object_ref (list));
 }
 
 static void


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