summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2008-09-03 23:12:55 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2008-09-03 23:12:55 +0000
commit266e482286669e10ae022148d4d1be835a3923e4 (patch)
tree4f018073de17cf29a16c9785cd0e81dabcaf1ecf
parent0138a289155569cc5a1fdf9e39276b13e3c72530 (diff)
downloadgtk+-266e482286669e10ae022148d4d1be835a3923e4.tar.gz
Bug 549711 – Race condition when loading gdk-pixbuf image modules
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. svn path=/trunk/; revision=21268
-rw-r--r--gdk-pixbuf/ChangeLog7
-rw-r--r--gdk-pixbuf/gdk-pixbuf-io.c79
2 files changed, 47 insertions, 39 deletions
diff --git a/gdk-pixbuf/ChangeLog b/gdk-pixbuf/ChangeLog
index f0fa408355..60101479af 100644
--- a/gdk-pixbuf/ChangeLog
+++ b/gdk-pixbuf/ChangeLog
@@ -1,3 +1,10 @@
+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.
+
2008-08-27 Matthias Clasen <mclasen@redhat.com>
Bug 549322 – Typo in gdk_pixbuf_save_to_buffer docs
diff --git a/gdk-pixbuf/gdk-pixbuf-io.c b/gdk-pixbuf/gdk-pixbuf-io.c
index a262c03ab2..6b248738b6 100644
--- a/gdk-pixbuf/gdk-pixbuf-io.c
+++ b/gdk-pixbuf/gdk-pixbuf-io.c
@@ -626,6 +626,20 @@ _gdk_pixbuf_load_module (GdkPixbufModule *image_module,
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 @@ _gdk_pixbuf_load_module (GdkPixbufModule *image_module,
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 @@ gdk_pixbuf_new_from_file (const char *filename,
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 @@ gdk_pixbuf_new_from_xpm_data (const char **data)
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 @@ gdk_pixbuf_real_save (GdkPixbuf *pixbuf,
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 @@ gdk_pixbuf_real_save_to_callback (GdkPixbuf *pixbuf,
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);