gresource: Improve resource unregistration performance slightly

Rather than iterating over the list twice: once to find the resource,
and once to re-find its link and delete it, just use
`g_list_delete_link()` to delete what was found.

This has the lovely side-effect of squashing a false positive from
scan-build, which thought there was a use-after-free of `resource` in
the caller, due to `g_resource_unref()` being called on it here.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #1767
This commit is contained in:
Philip Withnall 2024-04-12 15:13:33 +01:00
parent 1ed199a881
commit ae3bd19108
No known key found for this signature in database
GPG Key ID: DCDF5885B1F3ED73

View File

@ -1029,14 +1029,16 @@ g_resources_register_unlocked (GResource *resource)
static void static void
g_resources_unregister_unlocked (GResource *resource) g_resources_unregister_unlocked (GResource *resource)
{ {
if (g_list_find (registered_resources, resource) == NULL) GList *resource_link = g_list_find (registered_resources, resource);
if (resource_link == NULL)
{ {
g_warning ("Tried to remove not registered resource"); g_warning ("Tried to remove not registered resource");
} }
else else
{ {
registered_resources = g_list_remove (registered_resources, resource); g_resource_unref (resource_link->data);
g_resource_unref (resource); registered_resources = g_list_delete_link (registered_resources, resource_link);
} }
} }