[gnome-latex: 58/205] Avoid some memory leaks



commit fbda8a94b39211301c19da8463b7f2020a183b8a
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date:   Sat Sep 12 18:22:38 2009 +0200

    Avoid some memory leaks

 TODO            |  2 +-
 src/callbacks.c | 26 ++++++++++++++++++++++++--
 src/main.c      |  9 +++++++++
 src/prefs.c     |  2 ++
 src/symbols.c   |  1 +
 5 files changed, 37 insertions(+), 3 deletions(-)
---
diff --git a/TODO b/TODO
index 325a9d4..c8dd811 100644
--- a/TODO
+++ b/TODO
@@ -11,7 +11,7 @@ Wed Sep 9, 2009 to Wed Sep 16, 2009
        x if the window is maximised
        x position of the panes
 
-[-] check memory leaks
+[x] check memory leaks
 
 [-] new toolbar
        - structure: part, chapter, section, subsection, subsubsection, paragraph, subparagraph
diff --git a/src/callbacks.c b/src/callbacks.c
index 8e1b916..bcd8024 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -51,6 +51,7 @@ static gboolean find_next_match (const gchar *what, GtkSourceSearchFlags flags,
                gboolean backward, GtkTextIter *match_start, GtkTextIter *match_end);
 static void change_font_source_view (void);
 static void create_preferences (void);
+static void free_latexila (void);
 
 static GtkWidget *pref_dialog = NULL;
 
@@ -181,6 +182,7 @@ cb_quit (void)
        if (close_all ())
        {
                save_preferences (latexila.prefs);
+               free_latexila ();
                print_info ("Bye bye");
                gtk_main_quit ();
        }
@@ -1009,10 +1011,16 @@ close_document (gint index)
                                NULL
                );
 
+               gchar *doc_name;
+               if (latexila.active_doc->path == NULL)
+                       doc_name = g_strdup (_("New document"));
+               else
+                       doc_name = g_path_get_basename (latexila.active_doc->path);
+
                gchar *tmp = g_strdup_printf (
-                               _("Save changes to \"%s\" before closing?"),
-                               g_path_get_basename (latexila.active_doc->path));
+                               _("Save changes to \"%s\" before closing?"), doc_name);
                GtkWidget *label = gtk_label_new (tmp);
+               g_free (doc_name);
                g_free (tmp);
                GtkWidget *content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
                gtk_box_pack_start (GTK_BOX (content_area), label, TRUE, FALSE, 10);
@@ -1359,3 +1367,17 @@ create_preferences (void)
 
        gtk_widget_show_all (content_area);
 }
+
+static void
+free_latexila (void)
+{
+       g_free (latexila.prefs->command_view);
+       g_free (latexila.prefs->font_str);
+       g_free (latexila.prefs);
+       g_free (latexila.action_log);
+
+       for (int i = 0 ; i < 7 ; i++)
+               g_object_unref (latexila.symbols->list_stores[i]);
+
+       g_free (latexila.symbols);
+}
diff --git a/src/main.c b/src/main.c
index bab5eda..6ff2296 100644
--- a/src/main.c
+++ b/src/main.c
@@ -93,8 +93,15 @@ main (int argc, char *argv[])
        g_option_context_add_main_entries (context, options, NULL);
 #endif
        g_option_context_add_group (context, gtk_get_option_group (TRUE));
+
+       // TODO with valgrind there are a lot of memory leaks with this, can we do
+       // something?
        if (! g_option_context_parse (context, &argc, &argv, &error))
+       {
                print_error ("option parsing failed: %s\n", error->message);
+               g_error_free (error);
+               error = NULL;
+       }
 
 #ifdef LATEXILA_NLS_ENABLED
        gtk_init_with_args (&argc, &argv, NULL, options, LATEXILA_NLS_PACKAGE,
@@ -105,6 +112,8 @@ main (int argc, char *argv[])
        if (error != NULL)
                print_error ("%s", error->message);
 
+       g_option_context_free (context);
+
        /* localisation */
 #ifdef LATEXILA_NLS_ENABLED
        setlocale (LC_ALL, "");
diff --git a/src/prefs.c b/src/prefs.c
index ac57886..c6a4ea9 100644
--- a/src/prefs.c
+++ b/src/prefs.c
@@ -182,6 +182,7 @@ load_preferences (preferences_t *prefs)
        }
 
        print_info ("load user preferences: OK");
+       g_key_file_free (key_file);
 }
 
 void
@@ -252,6 +253,7 @@ save_preferences (preferences_t *prefs)
        g_free (rc_file);
        g_free (rc_path);
        g_free (key_file_data);
+       g_key_file_free (key_file);
 }
 
 void
diff --git a/src/symbols.c b/src/symbols.c
index 87b7885..00eb281 100644
--- a/src/symbols.c
+++ b/src/symbols.c
@@ -789,6 +789,7 @@ get_symbol_store (const struct symbol symbols[])
                                COLUMN_SYMBOL_TOOLTIP, tooltip,
                                -1);
                g_free (tooltip);
+               g_object_unref (pixbuf);
        }
 
        return symbol_store;


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