eel r2029 - in trunk: . eel
- From: alexl svn gnome org
- To: svn-commits-list gnome org
- Subject: eel r2029 - in trunk: . eel
- Date: Tue, 22 Jan 2008 14:46:18 +0000 (GMT)
Author: alexl
Date: Tue Jan 22 14:46:18 2008
New Revision: 2029
URL: http://svn.gnome.org/viewvc/eel?rev=2029&view=rev
Log:
2008-01-22 Alexander Larsson <alexl redhat com>
* eel/eel-string.c:
(eel_ref_str_unref):
Fix leak and tighten up a possible race
condition when a unique string is ressurected.
Modified:
trunk/ChangeLog
trunk/eel/eel-string.c
Modified: trunk/eel/eel-string.c
==============================================================================
--- trunk/eel/eel-string.c (original)
+++ trunk/eel/eel-string.c Tue Jan 22 14:46:18 2008
@@ -882,25 +882,26 @@
eel_ref_str_unref (eel_ref_str str)
{
volatile gint *count;
- gint res;
+ gint old_ref;
if (str == NULL)
return;
count = (volatile gint *)((char *)str - sizeof (gint));
- res = g_atomic_int_exchange_and_add (count, -1);
-
- if (res == 0) {
+ old_ref = g_atomic_int_get (count);
+ if (old_ref == 1) {
g_free ((char *)count);
- } else if (res == 0x80000000) {
+ } else if (old_ref == 0x80000001) {
G_LOCK (unique_ref_strs);
- /* Need to recheck after taking lock to avoid lookup in _get_unique() */
- if (g_atomic_int_get (count) == 0x80000000) {
+ /* Need to recheck after taking lock to avoid races with _get_unique() */
+ if (g_atomic_int_exchange_and_add (count, -1) == 0x80000001) {
g_hash_table_remove (unique_ref_strs, (char *)str);
- }
+ g_free ((char *)count);
+ }
G_UNLOCK (unique_ref_strs);
- g_free ((char *)count);
+ } else {
+ g_atomic_int_exchange_and_add (count, -1);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]