commit a02d3020be721b5babc6e01a8ce943b3d81259f0
Author: Javier Kohen <jko...@users.sourceforge.net>
Date:   Mon Jan 23 21:38:39 2012 +0100

    Fixed memory management in recurse_directories_internal.

 libgtkpod/file.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)
---
diff --git a/libgtkpod/file.c b/libgtkpod/file.c
index 7f3b3cc..51cbd4c 100644
--- a/libgtkpod/file.c
+++ b/libgtkpod/file.c
@@ -420,10 +420,15 @@ static void recurse_directories_internal(gchar *name, 
GSList **trknames, gboolea
                         nextfull = basepath;
                     }
 
-                    if (g_hash_table_lookup(*directories_seen, nextfull))
+                    if (g_hash_table_lookup(*directories_seen, nextfull)) {
                         continue;
-                    else
-                        g_hash_table_insert(*directories_seen, nextfull, 
nextfull);
+                    } else {
+                       /* The hash table is set-up to free the key,
+                        * but not the value, so we can pass a single
+                        * newly allocated string for both. */
+                       const gchar *key = g_strdup(nextfull);
+                       g_hash_table_insert(*directories_seen, key, key);
+                   }
 
                     if (descend || !g_file_test(nextfull, G_FILE_TEST_IS_DIR)) 
{
                         recurse_directories_internal(nextfull, trknames, 
descend, directories_seen);
@@ -453,7 +458,8 @@ static void recurse_directories_internal(gchar *name, 
GSList **trknames, gboolea
  *                      FALSE: don't enter subdirectories
  */
 static void recurse_directories_with_history(gchar *dir, GSList **trknames, 
gboolean descend) {
-    GHashTable *directories = g_hash_table_new_full(g_str_hash, g_str_equal, 
g_free, g_free);
+    /* Delete keys but not values. Users will set both to the same string. */
+    GHashTable *directories = g_hash_table_new_full(g_str_hash, g_str_equal, 
g_free, NULL);
     recurse_directories_internal(dir, trknames, descend, &directories);
     g_hash_table_destroy(directories);
 }

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
gtkpod-cvs2 mailing list
gtkpod-cvs2@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gtkpod-cvs2

Reply via email to