>From a836d14012ba23004b9a70ab0aadb556179378ca Mon Sep 17 00:00:00 2001 From: Andreas Winkelmann Date: Mon, 26 May 2014 17:50:21 +0200 Subject: [PATCH 2/3] Fixed a memory leak In Artist/Album-View the Album-List contains a row for a collection of all Albums for an Artist - the "" row. The attached List was not freed. Added a Column with a Boolean Value to the Model to be able to identify this Row. String-Comparison seems unsafe. Additional Lists to free these lists also. --- src/browser.c | 36 +++++++++++++++++++++++++++++++++--- src/browser.h | 1 + 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/browser.c b/src/browser.c index 07611c7..7db96fc 100644 --- a/src/browser.c +++ b/src/browser.c @@ -2139,6 +2139,32 @@ Browser_Artist_List_Set_Row_Appearance (GtkTreeIter *iter) void Browser_Album_List_Clear( void ) { GtkTreeSelection *selection; + GList *lstPtr; + GtkTreeIter selectedIter; + gboolean valid, allAlbumsRow; + + /* + * Get and free the attached Lists inside the "" Rows + */ + + valid = gtk_tree_model_get_iter_first( GTK_TREE_MODEL(albumListModel), &selectedIter ); + while ( valid ) + { + allAlbumsRow = FALSE; + lstPtr = NULL; + + gtk_tree_model_get( GTK_TREE_MODEL(albumListModel), &selectedIter, + ALBUM_ETFILE_LIST_POINTER, &lstPtr, + ALBUM_ALL_ALBUMS_ROW, &allAlbumsRow, + -1); + + if ( allAlbumsRow && lstPtr ) + { + g_list_free( lstPtr ); + } + + valid = gtk_tree_model_iter_next( GTK_TREE_MODEL(albumListModel), &selectedIter ); + } /* * Empty Model, Disable Browser_Album_List_Row_Selected() during clear because it is @@ -2178,7 +2204,7 @@ 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; @@ -2194,6 +2220,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 @@ -2216,7 +2243,9 @@ 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); @@ -3371,7 +3400,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 3560caf..4396f22 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 }; -- 1.8.4.5