[gtk+] Fix crash with theme resource file



commit fb0c53a0ed1daf5417bc90af848131416dc13d81
Author: Alexander Larsson <alexl redhat com>
Date:   Fri Feb 3 16:37:54 2012 +0100

    Fix crash with theme resource file
    
    The freeing the GResource in gtk_css_provider_reset caused problems
    because it was called from gtk_css_provider_load_from_path() inside
    gtk_css_provider_get_named(). We fix this by delaying the
    setting of priv->resource until we successfully loaded the file.

 gtk/gtkcssprovider.c |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 86b1c9c..a637eee 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -2925,18 +2925,24 @@ gtk_css_provider_get_named (const gchar *name,
 	  resource_file = g_build_filename (dir, "gtk.gresource", NULL);
 	  resource = g_resource_load (resource_file, NULL);
 	  if (resource != NULL)
-	    {
-	      provider->priv->resource = resource;
-	      g_resources_register (resource);
-	    }
+	    g_resources_register (resource);
 
           if (!gtk_css_provider_load_from_path (provider, path, NULL))
             {
+	      if (resource != NULL)
+		{
+		  g_resources_unregister (resource);
+		  g_resource_unref (resource);
+		}
               g_object_unref (provider);
               provider = NULL;
             }
           else
-            g_hash_table_insert (themes, g_strdup (key), provider);
+	    {
+	      /* Only set this after load success, as load_from_path will clear it */
+	      provider->priv->resource = resource;
+	      g_hash_table_insert (themes, g_strdup (key), provider);
+	    }
 
           g_free (path);
         }



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