diff options
author | Alexander Larsson <alexl@redhat.com> | 2009-09-08 10:54:35 +0200 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2009-09-08 10:54:35 +0200 |
commit | b698cf1932da077f07d99966a4c61568a1ae081e (patch) | |
tree | 8ae9e3b7fffa8f9a1b8d8648e58bf5cfd89b27b2 /eel | |
parent | 26714114eefe841c4b3eaa5a3a93b50ec69f76a8 (diff) | |
download | nautilus-b698cf1932da077f07d99966a4c61568a1ae081e.tar.gz |
Fix threadsafety issue in eel_ref_str_unref
Its not safe to just decrement count if we didn't read a 1, as we
could race with another decrement.
Diffstat (limited to 'eel')
-rw-r--r-- | eel/eel-string.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/eel/eel-string.c b/eel/eel-string.c index c72ab9535..15dc0b703 100644 --- a/eel/eel-string.c +++ b/eel/eel-string.c @@ -890,6 +890,7 @@ eel_ref_str_unref (eel_ref_str str) count = (volatile gint *)((char *)str - sizeof (gint)); + retry_atomic_decrement: old_ref = g_atomic_int_get (count); if (old_ref == 1) { g_free ((char *)count); @@ -901,8 +902,9 @@ eel_ref_str_unref (eel_ref_str str) g_free ((char *)count); } G_UNLOCK (unique_ref_strs); - } else { - g_atomic_int_exchange_and_add (count, -1); + } else if (!g_atomic_int_compare_and_exchange (count, + old_ref, old_ref - 1)) { + goto retry_atomic_decrement; } } |