gtk+ r21268 - trunk/gdk-pixbuf



Author: matthiasc
Date: Wed Sep  3 23:12:55 2008
New Revision: 21268
URL: http://svn.gnome.org/viewvc/gtk+?rev=21268&view=rev

Log:
2008-09-03  Matthias Clasen  <mclasen redhat com>

        Bug 549711 â Race condition when loading gdk-pixbuf image modules

        * gdk-pixbuf-io.c: Fix a race condition in module loading,
        spotted by Chris Lord.



Modified:
   trunk/gdk-pixbuf/ChangeLog
   trunk/gdk-pixbuf/gdk-pixbuf-io.c

Modified: trunk/gdk-pixbuf/gdk-pixbuf-io.c
==============================================================================
--- trunk/gdk-pixbuf/gdk-pixbuf-io.c	(original)
+++ trunk/gdk-pixbuf/gdk-pixbuf-io.c	Wed Sep  3 23:12:55 2008
@@ -626,6 +626,20 @@
 	GdkPixbufModuleFillInfoFunc fill_info = NULL;
         GdkPixbufModuleFillVtableFunc fill_vtable = NULL;
 
+	/* be extra careful, maybe the module initializes
+	 * the thread system
+	 */
+	if (g_threads_got_initialized) {
+		G_LOCK (init_lock);
+		locked = TRUE;
+	}
+
+	if (image_module->module != NULL) {
+		if (locked)
+			G_UNLOCK (init_lock);
+		return TRUE;
+	}
+
 #define try_module(format,id)						\
 	if (fill_info == NULL &&					\
 	    strcmp (image_module->module_name, #format) == 0) {		\
@@ -701,34 +715,26 @@
 		image_module->info = g_new0 (GdkPixbufFormat, 1);
 		(* fill_info) (image_module->info);
 
-                return TRUE;
+                ret = TRUE;
 	}
-
+	else {
 #ifdef USE_GMODULE
+		ret = _gdk_pixbuf_load_module_unlocked (image_module, error);
+#else
+		g_set_error (error,
+			     GDK_PIXBUF_ERROR,
+			     GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
+			     _("Image type '%s' is not supported",
+			     image_module->module_name);
 
-	/* be extra careful, maybe the module initializes
-	 * the thread system
-	 */
-	if (g_threads_got_initialized)
-	{
-		G_LOCK (init_lock);
-		locked = TRUE;
+		ret = FALSE;
+#endif
 	}
-	ret = _gdk_pixbuf_load_module_unlocked (image_module, error);
+
 	if (locked)
 		G_UNLOCK (init_lock);
-	return ret;
-
-#else
-	g_set_error (error,
-		     GDK_PIXBUF_ERROR,
-		     GDK_PIXBUF_ERROR_UNKNOWN_TYPE,
-		     _("Image type '%s' is not supported"),
-		     image_module->module_name);
-
-	return FALSE;
 
-#endif
+	return ret;
 }
 
 
@@ -967,12 +973,11 @@
                 return NULL;
         }
 
-	if (image_module->module == NULL)
-                if (!_gdk_pixbuf_load_module (image_module, error)) {
-			g_free (display_name);
-                        fclose (f);
-                        return NULL;
-                }
+        if (!_gdk_pixbuf_load_module (image_module, error)) {
+		g_free (display_name);
+        	fclose (f);
+        	return NULL;
+        }
 
 	fseek (f, 0, SEEK_SET);
 	pixbuf = _gdk_pixbuf_generic_image_load (image_module, f, error);
@@ -1561,12 +1566,10 @@
 		return NULL;
 	}
 
-	if (xpm_module->module == NULL) {
-                if (!_gdk_pixbuf_load_module (xpm_module, &error)) {
-                        g_warning ("Error loading XPM image loader: %s", error->message);
-                        g_error_free (error);
-                        return NULL;
-                }
+        if (!_gdk_pixbuf_load_module (xpm_module, &error)) {
+                g_warning ("Error loading XPM image loader: %s", error->message);
+                g_error_free (error);
+                return NULL;
         }
 
 	locked = _gdk_pixbuf_lock (xpm_module);
@@ -1659,9 +1662,8 @@
 	if (image_module == NULL)
 		return FALSE;
        
-	if (image_module->module == NULL)
-		if (!_gdk_pixbuf_load_module (image_module, error))
-			return FALSE;
+	if (!_gdk_pixbuf_load_module (image_module, error))
+		return FALSE;
 
 	locked = _gdk_pixbuf_lock (image_module);
 
@@ -1790,9 +1792,8 @@
 	if (image_module == NULL)
 		return FALSE;
        
-	if (image_module->module == NULL)
-		if (!_gdk_pixbuf_load_module (image_module, error))
-			return FALSE;
+	if (!_gdk_pixbuf_load_module (image_module, error))
+		return FALSE;
 
 	locked = _gdk_pixbuf_lock (image_module);
 



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