[glib: 10/12] gobject: Weaken an assertion in g_weak_ref_set()
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 10/12] gobject: Weaken an assertion in g_weak_ref_set()
- Date: Thu, 7 Jul 2022 11:52:20 +0000 (UTC)
commit 94ba14d5424c9304342a601cb9eb0842e56d8f51
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Sun Jul 3 14:56:44 2022 -0400
gobject: Weaken an assertion in g_weak_ref_set()
When weak references are being cleaned up, it is possible for the `qdata` for
both `quark_weak_locations` and `quark_weak_refs` to have been deallocated,
so that `g_datalist_id_get_data()` returns `NULL` for both. This happens
when `g_object_run_dispose()` is called for the target of a `GBinding`,
and is not an error.
See https://gitlab.gnome.org/GNOME/glib/-/issues/2676
gobject/gobject.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/gobject/gobject.c b/gobject/gobject.c
index df908984b7..2217e5c4b2 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -5059,16 +5059,22 @@ g_weak_ref_set (GWeakRef *weak_ref,
/* Remove the weak ref from the old object */
if (old_object != NULL)
{
+ gboolean in_weak_refs_notify;
+
weak_locations = g_datalist_id_get_data (&old_object->qdata, quark_weak_locations);
+ in_weak_refs_notify = g_datalist_id_get_data (&old_object->qdata, quark_weak_refs) == NULL;
/* for it to point to an object, the object must have had it added once */
- g_assert (weak_locations != NULL);
-
- *weak_locations = g_slist_remove (*weak_locations, weak_ref);
+ g_assert (weak_locations != NULL || in_weak_refs_notify);
- if (!*weak_locations)
+ if (weak_locations != NULL)
{
- weak_locations_free_unlocked (weak_locations);
- g_datalist_id_remove_no_notify (&old_object->qdata, quark_weak_locations);
+ *weak_locations = g_slist_remove (*weak_locations, weak_ref);
+
+ if (!*weak_locations)
+ {
+ weak_locations_free_unlocked (weak_locations);
+ g_datalist_id_remove_no_notify (&old_object->qdata, quark_weak_locations);
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]