Skip to content

gobject: Cleanup GWeakRef locations on object finalization

Marco Trevisan requested to merge 3v1n0/glib:always-cleanup-weak-locations into main

It can happen that a GWeakRef is added to an object while it's disposing (or even during finalizing) and this may happen in a thread that (weak) references an object while the disposal isn't completed yet or when using toggle references and switching to GWeakRef on notification (as the API suggests).

In such scenario the weak locations are not cleaned up when the object is finalized, and will point to a free'd area.

So, just after finalization and when we're sure that the object will be destroyed for sure, check again if there are new weak locations and unset them if any, as part of the qdata destruction.

Added various tests simulating this case.

Fixes: #2390 (closed)

Edited by Marco Trevisan

Merge request reports

Loading