segfault when deleting a GtkEditableLabel
Steps to reproduce
I have an editable label with a notify::editing
handler. Inside that handler I add an idle function with g_idle_add()
which deletes the editable label. However, after the label gets deleted I get a segfault inside GTK, because it adds a timeout of 100 ms on the editable label and it's already free'd by the time that runs.
Backtrace:
#0 0x00007ffff7546849 in gtk_event_controller_get_widget (controller=0x555583064210) at ../subprojects/gtk4/gtk/gtkeventcontroller.c:415
#1 0x00007ffff75363fd in stop_editing_soon (data=0x555583064210) at ../subprojects/gtk4/gtk/gtkeditablelabel.c:199
#2 0x00007ffff6f49052 in g_timeout_dispatch (source=0x555582636380, callback=<optimized out>, user_data=<optimized out>) at ../glib/glib/gmain.c:5017
#3 0x00007ffff6f4882b in g_main_dispatch (context=0x555555d74300) at ../glib/glib/gmain.c:3454
#4 g_main_context_dispatch (context=0x555555d74300) at ../glib/glib/gmain.c:4172
#5 0x00007ffff6f9fcc9 in g_main_context_iterate.constprop.0 (context=0x555555d74300, block=1, dispatch=1, self=<optimized out>) at ../glib/glib/gmain.c:4248
#6 0x00007ffff6f470e2 in g_main_context_iteration (context=context@entry=0x555555d74300, may_block=may_block@entry=1) at ../glib/glib/gmain.c:4313
#7 0x00007ffff711076e in g_application_run (application=0x555555d69a40, argc=<optimized out>, argv=0x7fffffffde58) at ../glib/gio/gapplication.c:2573
#8 0x00005555557c682f in main (argc=2, argv=0x7fffffffde58) at ../src/main.c:22
Related commit: 7be993b7
According to @otte it's a bug in gtkeditablelabel.c. Posting the transcript from IRC:
because nobody can be bothered to fix focus handling in popovers
it's that fun thing where focus moves from the toplevel to the popover
so Wayland goes "focus out, then focus in"
and GTK goes "focus out! our window lost focus, tell everyone"
and then GTK goes "oh great, we got focus again."
but because Wayland is so smart, that is equivalent to pressing alt-tab and then alt-tab again, refocusing something else - focus out, then focus in
fun fact: it means that if you press alt-tab twice quickly enough, the editable label is still editable!
anyway, GtkEditableLabel can't just run timeouts if it doesn't remove them when it gets unreffed
it could ref() itself, too, to avoid that
Version information
Version 4.9.3 as a subproject on Arch Linux.