gnome-vfs freeze break request



While debugging a nautilis bug i noticed a strange crash in the
gnome-vfs xdgmime system with valgrind. It seems likely that this was
caused by missed locks similar to those fixed in bug 170947. I've
repopened that bug and added a new patch that wraps the remaining
xdgmime calls with locks.

Is it ok to commit this to HEAD? (Patch is attached.)

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Alexander Larsson                                            Red Hat, Inc 
                   alexl redhat com    alla lysator liu se 
He's an old-fashioned soccer-playing filmmaker with a mysterious suitcase 
handcuffed to his arm. She's an artistic communist safe cracker operating on 
the wrong side of the law. They fight crime! 
Index: libgnomevfs/gnome-vfs-mime-info.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-mime-info.c,v
retrieving revision 1.88
diff -u -p -r1.88 gnome-vfs-mime-info.c
--- libgnomevfs/gnome-vfs-mime-info.c	8 May 2005 13:04:05 -0000	1.88
+++ libgnomevfs/gnome-vfs-mime-info.c	31 Aug 2005 11:00:07 -0000
@@ -69,6 +69,8 @@ static GList *mime_directories = NULL;
 
 static GHashTable *mime_entries = NULL;
 
+G_LOCK_EXTERN (gnome_vfs_mime_mutex);
+
 static gboolean
 does_string_contain_caps (const char *string)
 {
@@ -494,7 +496,9 @@ get_entry (const char *mime_type)
 	MimeEntry *entry;
 	char *path;
 
+	G_LOCK (gnome_vfs_mime_mutex);
 	umime =	xdg_mime_unalias_mime_type (mime_type);
+	G_UNLOCK (gnome_vfs_mime_mutex);
 
 	entry = g_hash_table_lookup (mime_entries, umime);
 	
Index: libgnomevfs/gnome-vfs-mime.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-mime.c,v
retrieving revision 1.57
diff -u -p -r1.57 gnome-vfs-mime.c
--- libgnomevfs/gnome-vfs-mime.c	23 Jun 2005 11:21:03 -0000	1.57
+++ libgnomevfs/gnome-vfs-mime.c	31 Aug 2005 11:00:07 -0000
@@ -59,7 +59,7 @@ struct FileDateTracker {
 #ifdef G_THREADS_ENABLED
 
 /* We lock this mutex whenever we modify global state in this module.  */
-G_LOCK_DEFINE_STATIC (mime_mutex);
+G_LOCK_DEFINE (gnome_vfs_mime_mutex);
 
 #endif /* G_LOCK_DEFINE_STATIC */
 
@@ -76,11 +76,11 @@ G_LOCK_DEFINE_STATIC (mime_mutex);
 void
 gnome_vfs_mime_shutdown (void)
 {
-	G_LOCK (mime_mutex);
+	G_LOCK (gnome_vfs_mime_mutex);
 
 	xdg_mime_shutdown ();
 
-	G_UNLOCK (mime_mutex);
+	G_UNLOCK (gnome_vfs_mime_mutex);
 }
 
 /**
@@ -121,9 +121,9 @@ gnome_vfs_mime_type_from_name_or_default
 		separator = filename;
 	}
 
-	G_LOCK (mime_mutex);
+	G_LOCK (gnome_vfs_mime_mutex);
 	mime_type = xdg_mime_get_mime_type_from_file_name (separator);
-	G_UNLOCK (mime_mutex);
+	G_UNLOCK (gnome_vfs_mime_mutex);
 
 	if (mime_type)
 		return mime_type;
@@ -173,9 +173,9 @@ _gnome_vfs_read_mime_from_buffer (GnomeV
 	GnomeVFSResult result = GNOME_VFS_OK;
 	const char *mime_type;
 
-	G_LOCK (mime_mutex);
+	G_LOCK (gnome_vfs_mime_mutex);
 	max_extents = xdg_mime_get_max_buffer_extents ();
-	G_UNLOCK (mime_mutex);
+	G_UNLOCK (gnome_vfs_mime_mutex);
 	max_extents = CLAMP (max_extents, 0, MAX_SNIFF_BUFFER_ALLOWED);
 
 	if (!buffer->read_whole_file) {
@@ -184,11 +184,11 @@ _gnome_vfs_read_mime_from_buffer (GnomeV
 	if (result != GNOME_VFS_OK && result != GNOME_VFS_ERROR_EOF) {
 		return NULL;
 	}
-	G_LOCK (mime_mutex);
+	G_LOCK (gnome_vfs_mime_mutex);
 
 	mime_type = xdg_mime_get_mime_type_for_data (buffer->buffer, buffer->buffer_length);
 
-	G_UNLOCK (mime_mutex);
+	G_UNLOCK (gnome_vfs_mime_mutex);
 
 	return mime_type;
 	
@@ -229,9 +229,12 @@ _gnome_vfs_get_mime_type_internal (Gnome
 					result = fn_result;
 				}
 				
-			} else if (fn_result && fn_result != XDG_MIME_TYPE_UNKNOWN &&
-				   xdg_mime_mime_type_subclass (fn_result, result)) {
-				result = fn_result;
+			} else if (fn_result && fn_result != XDG_MIME_TYPE_UNKNOWN) {
+				G_LOCK (gnome_vfs_mime_mutex);
+				if (xdg_mime_mime_type_subclass (fn_result, result)) {
+					result = fn_result;
+				}
+				G_UNLOCK (gnome_vfs_mime_mutex);
 			}
 			
 			return result;
@@ -243,9 +246,13 @@ _gnome_vfs_get_mime_type_internal (Gnome
 				 * accurate source of type information BUT _only_ if
 				 * the extension is a subtype of text/plain.
 				 */
-				if ((fn_result != NULL) && (fn_result != XDG_MIME_TYPE_UNKNOWN) &&
-				    xdg_mime_mime_type_subclass (fn_result, "text/plain")) {
-					return fn_result;
+				if ((fn_result != NULL) && (fn_result != XDG_MIME_TYPE_UNKNOWN)) {
+					G_LOCK (gnome_vfs_mime_mutex);
+					if (xdg_mime_mime_type_subclass (fn_result, "text/plain")) {
+						G_UNLOCK (gnome_vfs_mime_mutex);
+						return fn_result;
+					}
+					G_UNLOCK (gnome_vfs_mime_mutex);
 				}
 
 				/* Didn't find an extension match, assume plain text. */
@@ -607,9 +614,9 @@ gnome_vfs_mime_type_is_equal (const char
 	g_return_val_if_fail (a != NULL, FALSE);
 	g_return_val_if_fail (b != NULL, FALSE);
 
-	G_LOCK (mime_mutex);
+	G_LOCK (gnome_vfs_mime_mutex);
 	xdg_mime_mime_type_equal (a, b);
-	G_UNLOCK (mime_mutex);
+	G_UNLOCK (gnome_vfs_mime_mutex);
 
 	return FALSE;
 }
@@ -644,12 +651,12 @@ gnome_vfs_mime_type_get_equivalence (con
 	if (gnome_vfs_mime_type_is_equal (mime_type, base_mime_type)) {
 		return GNOME_VFS_MIME_IDENTICAL;
 	} else {
-		G_LOCK (mime_mutex);
+		G_LOCK (gnome_vfs_mime_mutex);
 		if (xdg_mime_mime_type_subclass (mime_type, base_mime_type)) {
-			G_UNLOCK (mime_mutex);
+			G_UNLOCK (gnome_vfs_mime_mutex);
 			return GNOME_VFS_MIME_PARENT;
 		}
-		G_UNLOCK (mime_mutex);
+		G_UNLOCK (gnome_vfs_mime_mutex);
 	}
 
 	return GNOME_VFS_MIME_UNRELATED;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]