mirror of
https://gitlab.gnome.org/GNOME/libsecret.git
synced 2025-01-11 06:28:51 +00:00
Fix secret_schema_unref detection of 0 refcount
g_atomic_int_add (&schema->refs, -1); will return the value of 'refs' _before_ adding -1 to it, so checking this value for 0 to see if the refcount dropped to 0 after adding -1 is not going to work and will cause a leak. Using g_atomic_int_dec_and_test() fixes this problem as this will return TRUE when the value drops to 0 after being decremented. https://bugzilla.gnome.org/show_bug.cgi?id=756766
This commit is contained in:
parent
20f35bfd92
commit
1b55291feb
@ -355,16 +355,12 @@ _secret_schema_ref_if_nonstatic (const SecretSchema *schema)
|
||||
void
|
||||
secret_schema_unref (SecretSchema *schema)
|
||||
{
|
||||
gint refs;
|
||||
gint i;
|
||||
|
||||
g_return_if_fail (schema != NULL);
|
||||
/* statically-allocated or invalid SecretSchema */
|
||||
g_return_if_fail (g_atomic_int_get (&schema->reserved) > 0);
|
||||
|
||||
refs = g_atomic_int_add (&schema->reserved, -1);
|
||||
if (refs < 0) {
|
||||
g_warning ("should not unreference a static or invalid SecretSchema");
|
||||
|
||||
} else if (refs == 0) {
|
||||
if (g_atomic_int_dec_and_test (&schema->reserved)) {
|
||||
gint i;
|
||||
g_free ((gpointer)schema->name);
|
||||
for (i = 0; i < G_N_ELEMENTS (schema->attributes); i++)
|
||||
g_free ((gpointer)schema->attributes[i].name);
|
||||
|
Loading…
Reference in New Issue
Block a user