mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-24 21:16:15 +01:00
gresource: Assert that resource has correct refcount when unregistering
This should fix a scan-build warning that `resource` is used-after-freeing in the final `g_resource_unref()` call in `g_static_resource_fini()`, as `g_resources_unregister_unlocked()` has already unreffed it. In reality, each resource has two strong refs on it while active, so the second unref is correct. Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
This commit is contained in:
parent
c8ea8cafd1
commit
86927c39e0
@ -1444,6 +1444,10 @@ g_static_resource_fini (GStaticResource *static_resource)
|
|||||||
resource = g_atomic_pointer_get (&static_resource->resource);
|
resource = g_atomic_pointer_get (&static_resource->resource);
|
||||||
if (resource)
|
if (resource)
|
||||||
{
|
{
|
||||||
|
/* There should be at least two references to the resource now: one for
|
||||||
|
* static_resource->resource, and one in the registered_resources list. */
|
||||||
|
g_assert (g_atomic_int_get (&resource->ref_count) >= 2);
|
||||||
|
|
||||||
g_atomic_pointer_set (&static_resource->resource, NULL);
|
g_atomic_pointer_set (&static_resource->resource, NULL);
|
||||||
g_resources_unregister_unlocked (resource);
|
g_resources_unregister_unlocked (resource);
|
||||||
g_resource_unref (resource);
|
g_resource_unref (resource);
|
||||||
|
Loading…
Reference in New Issue
Block a user