GObject doesn't support removing a weak reference in a GWeakNotify for the same object
@swilmet
Submitted by Sébastien Wilmet Link to original bug (#745678)
Description
GObject doesn't support removing a weak reference in a GWeakNotify for the same object.
Take for example:
- Three objects: A, B and C.
- Both objects B and C have a weak reference to object A.
- Object B has a strong reference to object C.
- When object A is destroyed, the GWeakNotify of object B is called, which unrefs and destroys object C.
- Object C's dispose() is called, which removes the weak reference to object A (if object C's GWeakNotify hasn't been called).
The latter point isn't supported by GObject, I'll attach a unit test. The backtrace looks like:
(process:1479): GLib-GObject-WARNING **: g_object_weak_unref: couldn't find weak ref 0x400dc1(0x2a)
#0 0x00007ffff7881cd5 in _g_log_abort (breakpoint=1) at gmessages.c:315
#1 0x00007ffff7882bb7 in g_logv (log_domain=0x7ffff7bc7a8f "GLib-GObject", log_level=G_LOG_LEVEL_WARNING, format=0x7ffff7bc89d0 "%s: couldn't find weak ref %p(%p)",
args=0x7fffffffd508) at gmessages.c:1041
#2 0x00007ffff7882ca5 in g_log (log_domain=0x7ffff7bc7a8f "GLib-GObject", log_level=G_LOG_LEVEL_WARNING, format=0x7ffff7bc89d0 "%s: couldn't find weak ref %p(%p)")
at gmessages.c:1079
#3 0x00007ffff7ba2353 in g_object_weak_unref (object=0x60f260, notify=0x400dc1 <weak_ref1>, data=0x2a) at gobject.c:2722
#4 0x0000000000400f48 in remove_other_weak_ref (data=0x21, object=0x60f260) at references.c:128
#5 0x00007ffff7ba1ffe in weak_refs_notify (data=0x60fa60) at gobject.c:2630
#6 0x00007ffff785858e in g_data_set_internal (datalist=0x60f270, key_id=53, new_data=0x0, new_destroy_func=0x0, dataset=0x0) at gdataset.c:407
#7 0x00007ffff7858a42 in g_datalist_id_set_data_full (datalist=0x60f270, key_id=53, data=0x0, destroy_func=0x0) at gdataset.c:670
#8 0x00007ffff7b9e09b in g_object_real_dispose (object=0x60f260) at gobject.c:1021
#9 0x00007ffff7ba2d63 in g_object_unref (_object=0x60f260) at gobject.c:3138
#10 0x00000000004013e7 in main (argc=1, argv=0x7fffffffd8b8) at references.c:235
Version: 2.43.x