eel r2029 - in trunk: . eel



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]