GTK4: Crash when closing GtkFileChooserNative
Hello,
Closing a GtkFileChooserNative dialog under GTK4 results in a crash, either by cancelling or opening a file.
Minimal application producing the crash (ran in a flatpak with GNOME 40 runtime):
import gi
gi.require_version("Gtk", "4.0")
from gi.repository import Gio, Gtk
class App(Gtk.Application):
def __init__(self, *args, **kwargs):
super().__init__(
*args,
application_id="org.example.Test",
flags=Gio.ApplicationFlags.FLAGS_NONE,
**kwargs
)
def do_startup(self):
Gtk.Application.do_startup(self)
def do_activate(self):
window = Gtk.ApplicationWindow(application=self, title="Test")
window.show()
def _show_file_chooser(button):
def _file_chooser_response(dialog, response):
print(response)
file_chooser = Gtk.FileChooserNative(
modal=True,
transient_for=window,
action=Gtk.FileChooserAction.OPEN
)
file_chooser.connect("response", _file_chooser_response)
file_chooser.show()
button = Gtk.Button(label="File chooser")
button.connect("clicked", _show_file_chooser)
window.set_child(button)
if __name__ == "__main__":
app = App()
app.run()
Backtrace with GDB
Thread 1 "python" received signal SIGSEGV, Segmentation fault.
#0 0x00007ffff601f33d in gtk_widget_has_grab (widget=widget@entry=0x5555565918e0)
at ../gtk/gtkwidget.c:5503
#1 0x00007ffff5ef6718 in gtk_grab_remove (widget=0x5555565918e0) at ../gtk/gtkmain.c:1759
#2 0x00007ffff6091592 in filechooser_portal_data_free (data=data@entry=0x5555557d20e0)
at ../gtk/gtkfilechoosernativeportal.c:73
#3 0x00007ffff60922b4 in gtk_file_chooser_native_portal_hide
(self=0x555555853370 [GtkFileChooserNative]) at ../gtk/gtkfilechoosernativeportal.c:528
#4 0x00007ffff5f0a2b6 in gtk_native_dialog_hide (self=0x555555853370 [GtkFileChooserNative])
at ../gtk/gtknativedialog.c:345
#5 0x00007ffff5f0a398 in gtk_native_dialog_dispose (object=0x555555853370 [GtkFileChooserNative])
at ../gtk/gtknativedialog.c:178
#6 0x00007ffff74414d3 in g_object_unref (_object=) at ../gobject/gobject.c:3486
#7 g_object_unref (_object=0x555555853370) at ../gobject/gobject.c:3416
#8 0x00007ffff60915b1 in filechooser_portal_data_free (data=data@entry=0x5555557d20e0) at ../gtk/gtkfilechoosernativeportal.c:77
#9 0x00007ffff60919fe in response_cb (connection=, sender_name=, object_path=, interface_name=, signal_name=, parameters=, user_data=0x555555853370) at ../gtk/gtkfilechoosernativeportal.c:176
#10 0x00007ffff72c64df in emit_signal_instance_in_idle_cb (data=0x7fffe401b420) at ../gio/gdbusconnection.c:3800
#11 0x00007ffff74dadbf in g_main_dispatch (context=0x555555792800) at ../glib/gmain.c:3337
#12 g_main_context_dispatch (context=0x555555792800) at ../glib/gmain.c:4055
#13 0x00007ffff74db168 in g_main_context_iterate (context=context@entry=0x555555792800, block=block@entry=1, dispatch=dispatch@entry=1, self=) at ../glib/gmain.c:4131
#14 0x00007ffff74db233 in g_main_context_iteration (context=context@entry=0x555555792800, may_block=may_block@entry=1) at ../glib/gmain.c:4196
#15 0x00007ffff729e66d in g_application_run (application=0x5555557dc2a0 [__main__+App], argc=-9900, argv=) at ../gio/gapplication.c:2560
#16 0x00007ffff7fbef75 in ffi_call_unix64 () at ../src/x86/unix64.S:101
#17 0x00007ffff7fbe369 in ffi_call_int (cif=, fn=, rvalue=, avalue=, closure=) at ../src/x86/ffi64.c:669
#18 0x00007ffff75faec5 in pygi_invoke_c_callable (function_cache=0x55555580ad20, state=, py_args=, py_kwargs=) at gi/pygi-invoke.c:684
#19 0x00007ffff75f1a2c in pygi_function_cache_invoke (function_cache=, py_args=, py_kwargs=) at gi/pygi-cache.c:862
#20 0x00007ffff7d25710 in PyObject_Call (callable=callable@entry=0x7ffff6806b30, args=args@entry=0x7ffff682d0a0, kwargs=kwargs@entry=0x7ffff77ff700) at ../Objects/call.c:246
#21 0x00007ffff7ce15aa in do_call_core (kwdict=0x7ffff77ff700, callargs=0x7ffff682d0a0, func=0x7ffff6806b30, tstate=0x555555580d80) at ../Python/ceval.c:5010
#22 _PyEval_EvalFrameDefault (f=, throwflag=) at ../Python/ceval.c:3559
#23 0x00007ffff7df5764 in _PyEval_EvalCodeWithName (_co=, globals=globals@entry=0x7ffff6865100, locals=locals@entry=0x0, args=, argcount=1, kwnames=0x0, kwargs=0x7ffff77da5b8, kwcount=0, kwstep=1, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0, name=0x7ffff7850670, qualname=0x7ffff6865330) at ../Python/ceval.c:4298
#24 0x00007ffff7df6851 in _PyFunction_Vectorcall (func=, stack=, nargsf=, kwnames=) at ../Objects/call.c:436
#25 0x00007ffff7ce3346 in _PyObject_Vectorcall (kwnames=0x0, nargsf=, args=0x7ffff77da5b0, callable=0x7ffff67f6d30) at ../Include/cpython/abstract.h:127
#26 call_function (kwnames=0x0, oparg=, pp_stack=, tstate=0x555555580d80) at ../Python/ceval.c:4963
#27 _PyEval_EvalFrameDefault (f=, throwflag=) at ../Python/ceval.c:3486
#28 0x00007ffff7df5764 in _PyEval_EvalCodeWithName (_co=_co@entry=0x7ffff76a69d0, globals=globals@entry=0x7ffff783c640, locals=locals@entry=0x7ffff783c640, args=args@entry=0x0, argcount=argcount@entry=0, kwnames=kwnames@entry=0x0, kwargs=0x0, kwcount=0, kwstep=2, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0, name=0x0, qualname=0x0) at ../Python/ceval.c:4298
#29 0x00007ffff7df5a5e in PyEval_EvalCodeEx (_co=_co@entry=0x7ffff76a69d0, globals=globals@entry=0x7ffff783c640, locals=locals@entry=0x7ffff783c640, args=args@entry=0x0, argcount=argcount@entry=0, kws=kws@entry=0x0, kwcount=0, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0) at ../Python/ceval.c:4327
#30 0x00007ffff7df5a8b in PyEval_EvalCode (co=co@entry=0x7ffff76a69d0, globals=globals@entry=0x7ffff783c640, locals=locals@entry=0x7ffff783c640) at ../Python/ceval.c:718
#31 0x00007ffff7df5e97 in run_eval_code_obj (co=co@entry=0x7ffff76a69d0, globals=globals@entry=0x7ffff783c640, locals=locals@entry=0x7ffff783c640) at ../Python/pythonrun.c:1165
#32 0x00007ffff7e5dcb1 in run_mod (mod=mod@entry=0x555555637160, filename=filename@entry=0x7ffff780cbf0, globals=globals@entry=0x7ffff783c640, locals=locals@entry=0x7ffff783c640, flags=flags@entry=0x7fffffffe208, arena=arena@entry=0x7ffff7834db0) at ../Python/pythonrun.c:1187
#33 0x00007ffff7e5e85f in pyrun_file (fp=fp@entry=0x555555559340, filename=filename@entry=0x7ffff780cbf0, start=start@entry=257, globals=globals@entry=0x7ffff783c640, locals=locals@entry=0x7ffff783c640, closeit=closeit@entry=1, flags=0x7fffffffe208) at ../Python/pythonrun.c:1084
#34 0x00007ffff7e6e4b5 in pyrun_simple_file (flags=0x7fffffffe208, closeit=1, filename=0x7ffff780cbf0, fp=0x555555559340) at ../Python/pythonrun.c:439
#35 PyRun_SimpleFileExFlags (fp=fp@entry=0x555555559340, filename=, closeit=closeit@entry=1, flags=flags@entry=0x7fffffffe208) at ../Python/pythonrun.c:472
#36 0x00007ffff7e6e96c in PyRun_AnyFileExFlags (fp=fp@entry=0x555555559340, filename=, closeit=closeit@entry=1, flags=flags@entry=0x7fffffffe208) at ../Python/pythonrun.c:90
#37 0x00007ffff7e71670 in pymain_run_file (cf=0x7fffffffe208, config=0x555555580170) at ../Modules/main.c:385
#38 pymain_run_python (exitcode=0x7fffffffe1fc) at ../Modules/main.c:610
#39 Py_RunMain () at ../Modules/main.c:689
#40 0x00007ffff7e71aa6 in pymain_main (args=0x7fffffffe300) at ../Modules/main.c:719
#41 Py_BytesMain (argc=, argv=) at ../Modules/main.c:743
#42 0x00007ffff7ac5062 in __libc_start_main (main=0x555555555050 , argc=2, argv=0x7fffffffe468, init=, fini=, rtld_fini=, stack_end=0x7fffffffe458) at ../csu/libc-start.c:308
#43 0x000055555555508e in _start () at ../sysdeps/x86_64/start.S:120