PyGObject Application crashes with "cannot allocate closure" errors.
Some Python Gtk3 & Gtk4 applications crash after a while with memory errors on Fedora 36, they worked fine in Fedora 35. The crash starts with repeated warnings followed by a memory allocation error:
** (gtk3bug.py:3785297): WARNING **: 20:50:00.861: could not allocate closure
** (gtk3bug.py:3785297): WARNING **: 20:50:00.861: could not allocate closure
** (gtk3bug.py:3785297): WARNING **: 20:50:00.861: could not allocate closure
** (gtk3bug.py:3785297): WARNING **: 20:50:00.862: could not allocate closure
...
***MEMORY-ERROR***: gtk3bug.py[3785297]: GSlice: failed to allocate 1008 bytes (alignment: 1024): Cannot allocate memory
The warning can be traced to a section of the code in gobject-introspection which makes a call to libffi. From the changelog, it appears the libffi closure API was changed between release 1.70 and 1.71. Fedora 35 uses version 1.70 while Fedora 36 uses version 1.72.
The same applications worked in prior Fedora versions. The crashes started after an upgrade to Fedora 36. It affects multiple unrelated Python Gtk3 & Gtk4 applications. All of them exhibit the same behavior. I have tested on different hardware to rule out a hardware problem. I've also reported the problem to the Fedora bugzilla https://bugzilla.redhat.com/show_bug.cgi?id=2112678
A minimal application demonstrating the issue is attached.gobject-bug.py