[easytag] Make g_file_list_add() accept a GFile
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag] Make g_file_list_add() accept a GFile
- Date: Fri, 13 Mar 2015 07:42:40 +0000 (UTC)
commit 35ecb696f6fb8e2781b57a0158d2d3c2d6df4b96
Author: David King <amigadave amigadave com>
Date: Thu Mar 12 21:55:36 2015 +0000
Make g_file_list_add() accept a GFile
Fix a long-standing filename memory leak when adding files to the main
file list.
src/easytag.c | 18 +++++++-----------
src/file_list.c | 14 +++++++-------
src/file_list.h | 2 +-
3 files changed, 15 insertions(+), 19 deletions(-)
---
diff --git a/src/easytag.c b/src/easytag.c
index d7b0d33..69c43b3 100644
--- a/src/easytag.c
+++ b/src/easytag.c
@@ -1004,18 +1004,17 @@ Read_Directory (const gchar *path_real)
for (l = FileList; l != NULL && !Main_Stop_Button_Pressed;
l = g_list_next (l))
{
- gchar *filename_real = l->data; /* Contains real filenames. */
+ GFile *file = l->data;
+ gchar *filename_real = g_file_get_path (file);
gchar *filename_utf8 = filename_to_display(filename_real);
msg = g_strdup_printf (_("File: ā%sā"), filename_utf8);
et_application_window_status_bar_message (window, msg, FALSE);
g_free(msg);
g_free(filename_utf8);
+ g_free (filename_real);
- /* Warning: Do not free filename_real because ET_Add_File.. uses it for
- * internal structures. */
- ETCore->ETFileList = et_file_list_add (ETCore->ETFileList,
- filename_real);
+ ETCore->ETFileList = et_file_list_add (ETCore->ETFileList, file);
/* Update the progress bar. */
fraction = (++progress_bar_index) / (double) nbrfile;
@@ -1027,8 +1026,7 @@ Read_Directory (const gchar *path_real)
gtk_main_iteration();
}
- /* Just free the list, not the data. */
- g_list_free (FileList);
+ g_list_free_full (FileList, g_object_unref);
et_application_window_progress_set_text (window, "");
/* Close window to quit recursion */
@@ -1172,12 +1170,10 @@ read_directory_recursively (GList *file_list, GFileEnumerator *dir_enumerator,
else if (type == G_FILE_TYPE_REGULAR &&
et_file_is_supported (file_name))
{
+ /* TODO: Use g_file_enumerator_get_child(). */
GFile *file = g_file_get_child (g_file_enumerator_get_container (dir_enumerator),
file_name);
- gchar *file_path = g_file_get_path (file);
- /*Do not free this file_path, it will be used by g_list*/
- file_list = g_list_append (file_list, file_path);
- g_object_unref (file);
+ file_list = g_list_append (file_list, file);
}
// Just to not block X events
diff --git a/src/file_list.c b/src/file_list.c
index 950479e..a770226 100644
--- a/src/file_list.c
+++ b/src/file_list.c
@@ -197,7 +197,7 @@ et_core_read_file_info (GFile *file,
*/
GList *
et_file_list_add (GList *file_list,
- gchar *filename)
+ GFile *file)
{
GList *result;
const ET_File_Description *description;
@@ -208,21 +208,21 @@ et_file_list_add (GList *file_list,
gchar *ETFileExtension;
guint ETFileKey;
guint undo_key;
- GFile *file;
GFileInfo *fileinfo;
- gchar *filename_utf8 = filename_to_display(filename);
+ gchar *filename;
+ gchar *filename_utf8;
const gchar *locale_lc_ctype = getenv("LC_CTYPE");
GError *error = NULL;
gboolean success;
- g_return_val_if_fail (filename != NULL, file_list);
-
- file = g_file_new_for_path (filename);
+ g_return_val_if_fail (file != NULL, file_list);
/* Primary Key for this file */
ETFileKey = ET_File_Key_New();
/* Get description of the file */
+ filename = g_file_get_path (file);
+ filename_utf8 = filename_to_display (filename);
description = ET_Get_File_Description (filename);
/* Get real extension of the file (keeping the case) */
@@ -412,7 +412,6 @@ et_file_list_add (GList *file_list,
* before saving */
fileinfo = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED,
G_FILE_QUERY_INFO_NONE, NULL, NULL);
- g_object_unref (file);
/* Attach all data defined above to this ETFile item */
ETFile = ET_File_Item_New();
@@ -479,6 +478,7 @@ et_file_list_add (GList *file_list,
//ET_Debug_Print_File_List(ETCore->ETFileList,__FILE__,__LINE__,__FUNCTION__);
+ g_free (filename);
g_free (filename_utf8);
return result;
diff --git a/src/file_list.h b/src/file_list.h
index 6630644..770c63b 100644
--- a/src/file_list.h
+++ b/src/file_list.h
@@ -27,7 +27,7 @@ G_BEGIN_DECLS
#include "file_tag.h"
#include "setting.h"
-GList * et_file_list_add (GList *file_list, gchar *filename);
+GList * et_file_list_add (GList *file_list, GFile *file);
void ET_Remove_File_From_File_List (ET_File *ETFile);
gboolean et_file_list_check_all_saved (GList *etfilelist);
void et_file_list_update_directory_name (GList *file_list, const gchar *old_path, const gchar *new_path);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]