PyGObject Application crashes with memory error after "cannot allocate closure" warnings.
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
Environment:
- Fedora release 36 (Thirty Six)
- gobject-introspection-1.72.0-1.fc36.x86_64
- python3-gobject-base-noarch-3.42.1-1.fc36.noarch
- python3-gobject-base-3.42.1-1.fc36.x86_64
- python3-gobject-3.42.1-1.fc36.x86_64
- gtk3-3.24.34-1.fc36.x86_64
- gtk4-4.6.7-1.fc36.x86_64
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 and to the gobject-introspection gobject-introspection#443 (closed).
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 gobject-introspection release 1.70 and 1.71. Fedora 35 uses version gi release 1.70 and pygobject version 3.42.0 while Fedora 36 uses gi version 1.72 and pygobject version 3.42.1.
A minimal application demonstrating the issue is attached. gobject-bug.py