Fix a double-free in GList/GSList #370

Merged
jwharm merged 2 commits from fix-list-double-free into main 2026-06-10 22:18:50 +02:00
Owner

When a GList or GSList contains GObjects, a double free bug makes the application segfault: The lifetime of the elements is managed by the InstanceCache, but the list tries to free them anyway.

The fix is to not free GObject elements. This was difficult to implement because, thanks to Java generic type erasure, we don't know the element type at runtime. So the GList and GSList constructors now take a GType argument, so we know the type.

When a GList or GSList contains GObjects, a double free bug makes the application segfault: The lifetime of the elements is managed by the InstanceCache, but the list tries to free them anyway. The fix is to not free GObject elements. This was difficult to implement because, thanks to Java generic type erasure, we don't know the element type at runtime. So the GList and GSList constructors now take a GType argument, so we know the type.
When a GList or GSList contains GObjects, a double free bug makes the
application segfault: The lifetime of the elements is managed by the
InstanceCache, but the list tries to free them anyway.

The fix is to not free GObject elements. This was difficult to
implement because, thanks to Java generic type erasure, we don't know
the element type at runtime. So the GList and GSList constructors now
take a GType argument, so we know the type.
This adds the old constructors back, annotated as deprecated.
They will be removed in a future java-gi release.
jwharm merged commit 31e086e693 into main 2026-06-10 22:18:50 +02:00
jwharm deleted branch fix-list-double-free 2026-06-10 22:18:57 +02:00
Sign in to join this conversation.
No description provided.