gobject: fix deadlock with g_weak_ref_set()

In general, we must not call out to external, unknown code while holding
a lock. That is prone to dead lock.

g_object_ref() can emit a toggle notification. In g_weak_ref_set(), we
must not do that while holding the lock.
This commit is contained in:
Thomas Haller
2023-12-23 20:06:03 +01:00
parent b397ef2122
commit e05623001b
2 changed files with 53 additions and 27 deletions

View File

@@ -731,11 +731,9 @@ weak_ref_in_toggle_notify_toggle_cb (gpointer data,
return;
/* We just got a second ref, while calling g_weak_ref_get().
* At this point, we hold a lock for the weak ref.
*
* FIXME: currently we would dead lock with the lines below.
* Test that taking another weak ref in this situation works.
*/
return;
g_weak_ref_init (&weak2, object);
g_assert_true (object == g_weak_ref_get (&weak2));