Hi, I'd like to commit the attached patch to gnome-vfs, but this breaks the code freeze. It modifies eggdesktopentries.c and gnome-vfs-mime-info-cache.c The eggdesktopentries.c changes have been reviewed by Ray Strode and are already in libegg. This fixes a pretty big leak (100KB on my system on a simple test program) each time a mimeinfo.cache file is (re)loaded. The gnome-vfs-mime-info-cache.c changes fix a memory cleanup issue which made gnome-vfs try to access freed memory under some conditions, this fixes bug #150467. Christophe
Index: libgnomevfs/gnome-vfs-mime-info-cache.c =================================================================== RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-mime-info-cache.c,v retrieving revision 1.4 diff -u -r1.4 gnome-vfs-mime-info-cache.c --- libgnomevfs/gnome-vfs-mime-info-cache.c 17 Aug 2004 20:26:24 -0000 1.4 +++ libgnomevfs/gnome-vfs-mime-info-cache.c 3 Sep 2004 08:52:00 -0000 @@ -33,6 +33,7 @@ #include "gnome-vfs-mime-monitor.h" #include "gnome-vfs-monitor.h" #include "gnome-vfs-ops.h" +#include "gnome-vfs-utils.h" #include "eggdesktopentries.h" #include "eggdirfuncs.h" @@ -56,7 +57,6 @@ extern void _gnome_vfs_mime_monitor_emit_data_changed (GnomeVFSMIMEMonitor *monitor); -static void free_mime_info_cache_map_list (GList *list); static void gnome_vfs_mime_info_cache_dir_init (GnomeVFSMimeInfoCacheDir *dir); static void gnome_vfs_mime_info_cache_dir_init_defaults_list (GnomeVFSMimeInfoCacheDir *dir); static GnomeVFSMimeInfoCacheDir *gnome_vfs_mime_info_cache_dir_new (const char *path); @@ -76,11 +76,19 @@ static GnomeVFSMimeInfoCache *mime_info_cache = NULL; G_LOCK_DEFINE_STATIC (mime_info_cache); + +static void +destroy_info_cache_value (gpointer key, GList *value, gpointer data) +{ + gnome_vfs_list_deep_free (value); +} + static void -free_mime_info_cache_map_list (GList *list) +destroy_info_cache_map (GHashTable *info_cache_map) { - g_list_foreach (list, (GFunc) g_free, NULL); - g_list_free (list); + g_hash_table_foreach (info_cache_map, (GHFunc)destroy_info_cache_value, + NULL); + g_hash_table_destroy (info_cache_map); } static gboolean @@ -109,7 +117,7 @@ { EggDesktopEntries *entries; GError *load_error; - gchar *filename, **desktop_file_ids, **mime_types; + gchar *filename, **mime_types; int i; static gchar *allowed_start_groups[] = { "MIME Cache", NULL }; struct stat buf; @@ -125,12 +133,12 @@ return; if (dir->mime_info_cache_map != NULL) { - g_hash_table_destroy (dir->mime_info_cache_map); + destroy_info_cache_map (dir->mime_info_cache_map); } dir->mime_info_cache_map = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, - (GDestroyNotify) free_mime_info_cache_map_list); + NULL); filename = g_build_filename (dir->path, "mimeinfo.cache", NULL); @@ -162,6 +170,7 @@ goto error; for (i = 0; mime_types[i] != NULL; i++) { + gchar **desktop_file_ids; desktop_file_ids = egg_desktop_entries_get_string_list (entries, "MIME Cache", mime_types[i], @@ -365,7 +374,7 @@ if (dir == NULL) return; if (dir->mime_info_cache_map != NULL) { - g_hash_table_destroy (dir->mime_info_cache_map); + destroy_info_cache_map (dir->mime_info_cache_map); dir->mime_info_cache_map = NULL; } Index: libgnomevfs/eggdesktopentries.c =================================================================== RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/eggdesktopentries.c,v retrieving revision 1.7 diff -u -r1.7 eggdesktopentries.c --- libgnomevfs/eggdesktopentries.c 18 Aug 2004 13:25:55 -0000 1.7 +++ libgnomevfs/eggdesktopentries.c 3 Sep 2004 08:52:01 -0000 @@ -409,6 +409,9 @@ if (entries->parse_buffer) g_string_free (entries->parse_buffer, TRUE); + g_strfreev (entries->legal_start_groups); + g_free (entries->default_group_name); + tmp = entries->groups; while (tmp != NULL) { @@ -600,10 +603,7 @@ entry = g_new0 (EggDesktopEntry, 1); entry->key = NULL; - - entry->value = g_new (char, length + 1); - strncpy (entry->value, line, length); - entry->value[length] = '\0'; + entry->value = g_strndup (line, length); entries->current_group->entries = g_list_prepend (entries->current_group->entries, entry); } @@ -1703,6 +1703,18 @@ entries->current_group = group; } + +static void +entry_free (EggDesktopEntry *entry) +{ + if (entry != NULL) + { + g_free (entry->key); + g_free (entry->value); + g_free (entry); + } +} + static void egg_desktop_entries_remove_group_node (EggDesktopEntries *entries, GList *group_node) @@ -1730,7 +1742,7 @@ g_free ((gchar *) group->name); - g_list_foreach (group->entries, (GFunc) g_free, NULL); + g_list_foreach (group->entries, (GFunc) entry_free, NULL); g_list_free (group->entries); group->entries = NULL;
Attachment:
signature.asc
Description: Ceci est une partie de message =?ISO-8859-1?Q?num=E9riquement?= =?ISO-8859-1?Q?_sign=E9e?=