mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-24 19:22:11 +01:00
GTimeZone: fix non-threadsafe refcounting
In the previous code, if the timezone was pulled out of the cache again just as the last reference was being dropped, the cache code will increase its refcount and return it while the unref code was freeing it. Protect against that. Note that this patch is not a straight cherry-pick of the one from master. It follows closer to the solution that was originally recommended in the bug and holds the mutex during every unref operation. Because we don't have the GTimeZoneMonitor changes involved here, it's a little bit more elegant (due to no early exit condition). Also, it's the stable release, and I have more confidence in it (even if it's probably slower). Closes #646435.
This commit is contained in:
parent
8c24ea5f49
commit
e781c26b25
@ -164,11 +164,10 @@ g_time_zone_unref (GTimeZone *tz)
|
|||||||
{
|
{
|
||||||
g_assert (tz->ref_count > 0);
|
g_assert (tz->ref_count > 0);
|
||||||
|
|
||||||
|
G_LOCK(time_zones);
|
||||||
if (g_atomic_int_dec_and_test (&tz->ref_count))
|
if (g_atomic_int_dec_and_test (&tz->ref_count))
|
||||||
{
|
{
|
||||||
G_LOCK(time_zones);
|
|
||||||
g_hash_table_remove (time_zones, tz->name);
|
g_hash_table_remove (time_zones, tz->name);
|
||||||
G_UNLOCK(time_zones);
|
|
||||||
|
|
||||||
if (tz->zoneinfo)
|
if (tz->zoneinfo)
|
||||||
g_buffer_unref (tz->zoneinfo);
|
g_buffer_unref (tz->zoneinfo);
|
||||||
@ -177,6 +176,7 @@ g_time_zone_unref (GTimeZone *tz)
|
|||||||
|
|
||||||
g_slice_free (GTimeZone, tz);
|
g_slice_free (GTimeZone, tz);
|
||||||
}
|
}
|
||||||
|
G_UNLOCK(time_zones);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user