[gnome-latex: 112/205] File browser: memory problems correction



commit 3ea288f53bfc38ad6b8aa61ab0b3201bb4658e57
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date:   Mon Nov 9 01:17:08 2009 +0100

    File browser: memory problems correction
    
    I don't know exactly why but with big directories like /usr/bin there
    were memory problems with this warning:
    Pango-WARNING **: Invalid UTF-8 string passed to pango_layout_set_text()
    
    So the solution is to make copies of the file names.

 src/file_browser.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/src/file_browser.c b/src/file_browser.c
index eb422ae..710ad1c 100644
--- a/src/file_browser.c
+++ b/src/file_browser.c
@@ -132,14 +132,19 @@ fill_list_store_with_current_dir (void)
                gchar *full_path = g_build_filename (latexila.prefs.file_browser_dir,
                                read_name, NULL);
 
+               // make a copy of read_name, else there are memory errors if the
+               // directory is very big (/usr/bin for example)
+               gchar *tmp = g_strdup (read_name);
+
                if (g_file_test (full_path, G_FILE_TEST_IS_DIR))
-                       directory_list = g_list_prepend (directory_list, (gpointer) read_name);
+                       directory_list = g_list_prepend (directory_list, (gpointer) tmp);
                else
-                       file_list = g_list_prepend (file_list, (gpointer) read_name);
+                       file_list = g_list_prepend (file_list, (gpointer) tmp);
 
                g_free (full_path);
        }
 
+       g_dir_close (dir);
 
        // sort the lists in alphabetical order
        directory_list = g_list_sort (directory_list, sort_list_alphabetical_order);
@@ -169,6 +174,7 @@ fill_list_store_with_current_dir (void)
                                COLUMN_FILE_BROWSER_FILE, directory,
                                -1);
 
+               g_free (directory);
                current = g_list_next (current);
        }
 
@@ -188,10 +194,10 @@ fill_list_store_with_current_dir (void)
                                COLUMN_FILE_BROWSER_FILE, file,
                                -1);
 
+               g_free (file);
                current = g_list_next (current);
        }
 
-       g_dir_close (dir);
        g_object_unref (pixbuf_dir);
        g_object_unref (pixbuf_file);
        g_list_free (directory_list);


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