[easytag/wip/application-window: 6/42] Fixed a album/artist view memory leak



commit 8ca5776f4517de59cf4cea9cc1e6a55b3985058a
Author: Andreas Winkelmann <ml awinkelmann de>
Date:   Fri Jun 6 23:10:42 2014 +0100

    Fixed a album/artist view memory leak
    
    In artist/album view the album list store contains a row for a
    collection of all albums for an artist - the "<All Albums>" row. The
    attached GList was not freed.
    
    Add a column with a boolean value to the model to be able to identify
    this row, as a simple string comparison seems unsafe.

 src/browser.c |   33 ++++++++++++++++++++++++++++++---
 src/browser.h |    1 +
 2 files changed, 31 insertions(+), 3 deletions(-)
---
diff --git a/src/browser.c b/src/browser.c
index 97e0227..8f10b10 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -2139,6 +2139,31 @@ void
 browser_album_model_clear (void)
 {
     GtkTreeSelection *selection;
+    gboolean valid;
+    GtkTreeIter iter;
+
+    /* Free the attached list in the "all albums" row. */
+    valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (albumListModel),
+                                           &iter);
+
+    while (valid)
+    {
+        GList *l;
+        gboolean all_albums_row = FALSE;
+
+        gtk_tree_model_get (GTK_TREE_MODEL (albumListModel), &iter,
+                            ALBUM_ETFILE_LIST_POINTER, &l,
+                            ALBUM_ALL_ALBUMS_ROW, &all_albums_row, -1);
+
+        if (all_albums_row && l)
+        {
+            g_list_free (l);
+            break;
+        }
+
+        valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (albumListModel),
+                                          &iter);
+    }
 
     /* Empty model, disable Browser_Album_List_Row_Selected () during clear
      * because it is called and crashed. */
@@ -2179,7 +2204,6 @@ Browser_Album_List_Load_Files (GList *albumlist, ET_File *etfile_to_select)
     selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserAlbumList));
 
     // Create a first row to select all albums of the artist
-    // FIX ME : the attached list must be freed!
     for (l = albumlist; l != NULL; l = g_list_next (l))
     {
         GList *etfilelist_tmp;
@@ -2195,6 +2219,7 @@ Browser_Album_List_Load_Files (GList *albumlist, ET_File *etfile_to_select)
                                        ALBUM_NUM_FILES,
                                        g_list_length (g_list_first (etfilelist)),
                                        ALBUM_ETFILE_LIST_POINTER, etfilelist,
+                                       ALBUM_ALL_ALBUMS_ROW, TRUE,
                                        -1);
 
     // Create a line for each album of the artist
@@ -2217,7 +2242,8 @@ Browser_Album_List_Load_Files (GList *albumlist, ET_File *etfile_to_select)
                                            ALBUM_NUM_FILES,
                                            g_list_length (g_list_first (etfilelist)),
                                            ALBUM_ETFILE_LIST_POINTER,
-                                           etfilelist, -1);
+                                           etfilelist,
+                                           ALBUM_ALL_ALBUMS_ROW, FALSE, -1);
 
         g_object_unref (icon);
 
@@ -3372,7 +3398,8 @@ GtkWidget *Create_Browser_Items (GtkWidget *parent)
                                          G_TYPE_POINTER,
                                          PANGO_TYPE_STYLE,
                                          G_TYPE_INT,
-                                         GDK_TYPE_COLOR);
+                                         GDK_TYPE_COLOR,
+                                         G_TYPE_BOOLEAN);
 
     BrowserAlbumList = gtk_tree_view_new_with_model(GTK_TREE_MODEL(albumListModel));
     g_object_unref (albumListModel);
diff --git a/src/browser.h b/src/browser.h
index db6850c..c1bcfb5 100644
--- a/src/browser.h
+++ b/src/browser.h
@@ -121,6 +121,7 @@ enum
     ALBUM_FONT_STYLE,
     ALBUM_FONT_WEIGHT,
     ALBUM_ROW_FOREGROUND,
+    ALBUM_ALL_ALBUMS_ROW,
     ALBUM_COLUMN_COUNT
 };
 


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