changeset 4122:e1468d0b118d

Make skin data to be freed after skin usage (= on skin changes) (Bugzilla #48)
author Jussi Judin <jjudin+audacious@iki.fi>
date Tue, 25 Dec 2007 14:14:33 -0600
parents bb35123048fb
children ab59718d8704
files src/audacious/skin.c src/audacious/ui_main.c
diffstat 2 files changed, 33 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/skin.c	Tue Dec 25 19:12:35 2007 +0100
+++ b/src/audacious/skin.c	Tue Dec 25 14:14:33 2007 -0600
@@ -204,6 +204,12 @@
     return skin;
 }
 
+/**
+ * Frees the data associated for skin.
+ *
+ * Does not free skin itself or lock variable so that the skin can immediately
+ * populated with new skin data if needed.
+ */
 void
 skin_free(Skin * skin)
 {
@@ -211,12 +217,10 @@
 
     g_return_if_fail(skin != NULL);
 
-    skin_lock(skin);
-
     for (i = 0; i < SKIN_PIXMAP_COUNT; i++)
         skin_pixmap_free(&skin->pixmaps[i]);
 
-    for (i = 0; i < SKIN_PIXMAP_COUNT; i++) {
+    for (i = 0; i < SKIN_MASK_COUNT; i++) {
         if (skin->masks[i])
             g_object_unref(skin->masks[i]);
         if (skin->ds_masks[i])
@@ -226,8 +230,17 @@
         skin->ds_masks[i] = NULL;
     }
 
+    for (i = 0; i < SKIN_COLOR_COUNT; i++) {
+        if (skin->colors[i])
+            g_free(skin->colors[i]);
+
+        skin->colors[i] = NULL;
+    }
+
+    g_free(skin->path);
+    skin->path = NULL;
+
     skin_set_default_vis_color(skin);
-    skin_unlock(skin);
 }
 
 void
@@ -531,6 +544,12 @@
     return TRUE;
 }
 
+void cleanup_skins()
+{
+    skin_destroy(bmp_active_skin);
+}
+
+
 /*
  * Opens and parses a skin's hints file.
  * Hints files are somewhat like "scripts" in Winamp3/5.
@@ -1476,6 +1495,7 @@
 {
     GtkSettings *settings;
     gchar *cpath, *gtkrcpath;
+    gchar *newpath;
 
     AUDDBG("\n");
 
@@ -1490,14 +1510,17 @@
         AUDDBG("skin %s already loaded\n", path);
         return FALSE;
     }
-    
+
+    // skin_free() frees skin->path and variable path can actually be skin->path
+    // and we want to get the path before possibly freeing it.
+    newpath = g_strdup(path);
+    skin_free(skin);
+    skin->path = newpath;
+
     memset(&(skin->properties), 0, sizeof(SkinProperties)); /* do it only if all tests above passed! --asphyx */
       
     skin_current_num++;
 
-    skin->path = g_strdup(path);
-
-
     settings = gtk_settings_get_default();
     
     if (original_gtk_theme != NULL)
--- a/src/audacious/ui_main.c	Tue Dec 25 19:12:35 2007 +0100
+++ b/src/audacious/ui_main.c	Tue Dec 25 14:14:33 2007 -0600
@@ -405,6 +405,8 @@
 
     gtk_main_quit();
 
+    cleanup_skins();
+
     exit(EXIT_SUCCESS);
 }