[balsa] Plug various memory leaks.



commit e89220412e4e36b2e6dace66d3b9c9ada7b52b38
Author: Pawel Salek <pawsa0 gmail com>
Date:   Thu May 6 20:44:33 2010 +0200

    Plug various memory leaks.
    
    * libinit_balsa/assistant_page_defclient.c: free memory.
    * libinit_balsa/assistant_page_{directory,user}.c: ditto.
    * src/balsa-app.c: free memory on exit.
    * src/balsa-icons.[hc]: ditto by providing "unregister" functions.
    * src/main-window.c: unregister the pixmaps.
    * src/main.c: free configuration on exit.
    * src/save-restore.c: do not leak memory.

 ChangeLog                                |   10 ++++++++++
 libinit_balsa/assistant_page_defclient.c |    1 +
 libinit_balsa/assistant_page_directory.c |    7 +++++--
 libinit_balsa/assistant_page_user.c      |    2 ++
 src/balsa-app.c                          |    7 ++++++-
 src/balsa-icons.c                        |   13 +++++++++++--
 src/balsa-icons.h                        |    5 +++--
 src/main-window.c                        |    5 +++--
 src/main.c                               |    2 ++
 src/save-restore.c                       |   12 ++++++------
 10 files changed, 49 insertions(+), 15 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6988bfb..f296eef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2010-05-06  Pawel Salek
+
+	* libinit_balsa/assistant_page_defclient.c: free memory.
+	* libinit_balsa/assistant_page_{directory,user}.c: ditto.
+	* src/balsa-app.c: free memory on exit.
+	* src/balsa-icons.[hc]: ditto by providing "unregister" functions.
+	* src/main-window.c: unregister the pixmaps.
+	* src/main.c: free configuration on exit.
+	* src/save-restore.c: do not leak memory.
+
 2010-05-01  Pawel Salek
 
 	* src/balsa-message.c: handle expunge events arriving between
diff --git a/libinit_balsa/assistant_page_defclient.c b/libinit_balsa/assistant_page_defclient.c
index 78f5902..522ddf7 100644
--- a/libinit_balsa/assistant_page_defclient.c
+++ b/libinit_balsa/assistant_page_defclient.c
@@ -104,6 +104,7 @@ balsa_druid_page_defclient(GtkAssistant *druid, GdkPixbuf *default_logo)
     balsa_druid_page_defclient_init(defclient, page, druid);
     /* This one is ready to pass through. */
     gtk_assistant_set_page_complete(druid, page, TRUE);
+    g_object_weak_ref(G_OBJECT(druid), (GWeakNotify)g_free, defclient);
 }
 
 static void
diff --git a/libinit_balsa/assistant_page_directory.c b/libinit_balsa/assistant_page_directory.c
index b133e8a..f06ead8 100644
--- a/libinit_balsa/assistant_page_directory.c
+++ b/libinit_balsa/assistant_page_directory.c
@@ -81,7 +81,7 @@ unconditional_mailbox(const gchar * path, const gchar * prettyname,
     gchar *index;
     char tmp[32] = "/tmp/balsa.XXXXXX";
     ciss_url_t url;
-    gboolean ssl = FALSE;
+    gboolean ssl = FALSE, is_remote = FALSE;
 
     if ((*error) != NULL)
         return;
@@ -118,11 +118,13 @@ unconditional_mailbox(const gchar * path, const gchar * prettyname,
         *box = (LibBalsaMailbox *) libbalsa_mailbox_imap_new();
         libbalsa_mailbox_imap_set_path((LibBalsaMailboxImap *) * box,
                                        url.path);
+        is_remote = TRUE;
         break;
     case U_POPS:
         ssl = TRUE;
     case U_POP:
         *box = (LibBalsaMailbox *) libbalsa_mailbox_pop3_new();
+        is_remote = TRUE;
         break;
     case U_FILE:
         *box =
@@ -132,7 +134,7 @@ unconditional_mailbox(const gchar * path, const gchar * prettyname,
         *box = (LibBalsaMailbox *) libbalsa_mailbox_local_new(path, TRUE);
     }
 
-    if (url.host && LIBBALSA_IS_MAILBOX_REMOTE(*box)) {
+    if (is_remote) {
         libbalsa_server_set_host(LIBBALSA_MAILBOX_REMOTE_SERVER(*box),
                                  url.host, ssl);
         libbalsa_server_set_username(LIBBALSA_MAILBOX_REMOTE_SERVER(*box),
@@ -264,6 +266,7 @@ balsa_druid_page_directory(GtkAssistant * druid, GdkPixbuf * default_logo)
     gtk_assistant_set_page_title(druid, dir->page, _("Mail Files"));
     gtk_assistant_set_page_header_image(druid, dir->page, default_logo);
     balsa_druid_page_directory_init(dir, dir->page, druid);
+    g_object_weak_ref(G_OBJECT(druid), (GWeakNotify)g_free, dir);
 }
 
 static void
diff --git a/libinit_balsa/assistant_page_user.c b/libinit_balsa/assistant_page_user.c
index 83bebc1..4680928 100644
--- a/libinit_balsa/assistant_page_user.c
+++ b/libinit_balsa/assistant_page_user.c
@@ -172,6 +172,7 @@ balsa_druid_page_user(GtkAssistant * druid, GdkPixbuf * default_logo)
     g_signal_connect(G_OBJECT(druid), "prepare",
                      G_CALLBACK(balsa_druid_page_user_prepare),
                      user);
+    g_object_weak_ref(G_OBJECT(druid), (GWeakNotify)g_free, user);
 }
 
 static void
@@ -288,6 +289,7 @@ balsa_druid_page_user_next(GtkAssistant * druid, GtkWidget * page,
         ident = LIBBALSA_IDENTITY(libbalsa_identity_new_with_name
 				  (_("Default Identity")));
         balsa_app.identities = g_list_append(NULL, ident);
+        balsa_app.current_ident = ident;
 	if(domain)
 	    libbalsa_identity_set_domain(ident, domain+1);
     } else {
diff --git a/src/balsa-app.c b/src/balsa-app.c
index 93060a8..1859610 100644
--- a/src/balsa-app.c
+++ b/src/balsa-app.c
@@ -466,7 +466,12 @@ balsa_app_destroy(void)
     g_slist_free(balsa_app.filters);
     balsa_app.filters = NULL;
 
-    /* g_slist_free(opt_attach_list); */
+
+    g_list_foreach(balsa_app.identities, (GFunc)g_object_unref, NULL);
+    g_list_free(balsa_app.identities);
+    balsa_app.identities = NULL;
+
+
     g_object_unref(balsa_app.colormap);
     if(balsa_app.debug) g_print("balsa_app: Finished cleaning up.\n");
 }
diff --git a/src/balsa-icons.c b/src/balsa-icons.c
index 54be173..00f278e 100644
--- a/src/balsa-icons.c
+++ b/src/balsa-icons.c
@@ -160,7 +160,7 @@ load_balsa_pixmap(GtkIconTheme *icon_theme, GtkIconFactory *factory,
 }
 
 void
-register_balsa_pixmaps(void)
+balsa_register_pixmaps(void)
 {
     const balsa_pixmap_t balsa_icons[] = {
 	/* icons for buttons and menus (24x24 and 16x16) */
@@ -302,7 +302,16 @@ register_balsa_pixmaps(void)
 }
 
 void
-register_balsa_pixbufs(GtkWidget * widget)
+balsa_unregister_pixmaps(void)
+{
+    if (balsa_icon_table) {
+        g_hash_table_destroy(balsa_icon_table);
+        balsa_icon_table = NULL;
+    }
+}
+
+void
+balsa_register_pixbufs(GtkWidget * widget)
 {
     static struct {
 	void (*set_icon) (GdkPixbuf *);
diff --git a/src/balsa-icons.h b/src/balsa-icons.h
index 6e70ff5..ab5f48c 100644
--- a/src/balsa-icons.h
+++ b/src/balsa-icons.h
@@ -93,8 +93,9 @@
 
 #define BALSA_PIXMAP_DROP_DOWN                  "balsa_drop_down"
 
-void register_balsa_pixmaps(void);
-void register_balsa_pixbufs(GtkWidget * widget);
+void balsa_register_pixmaps(void);
+void balsa_unregister_pixmaps(void);
+void balsa_register_pixbufs(GtkWidget * widget);
 void balsa_icon_create(const gchar ** data, GdkPixmap ** pmap,
                        GdkBitmap ** bmap);
 const gchar * balsa_icon_id(const gchar * name);
diff --git a/src/main-window.c b/src/main-window.c
index bb9292e..fa5f4ea 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -1651,7 +1651,7 @@ balsa_window_new()
 
     /* Call to register custom balsa pixmaps with GNOME_STOCK_PIXMAPS
      * - allows for grey out */
-    register_balsa_pixmaps();
+    balsa_register_pixmaps();
 
     window = g_object_new(BALSA_TYPE_WINDOW, NULL);
     window->vbox = gtk_vbox_new(FALSE, 0);
@@ -1659,7 +1659,7 @@ balsa_window_new()
     gtk_container_add(GTK_CONTAINER(window), window->vbox);
 
     gtk_window_set_title(GTK_WINDOW(window), "Balsa");
-    register_balsa_pixbufs(GTK_WIDGET(window));
+    balsa_register_pixbufs(GTK_WIDGET(window));
 
     model = balsa_window_get_toolbar_model();
     ui_manager = balsa_window_ui_manager_new(window);
@@ -2581,6 +2581,7 @@ balsa_window_destroy(GtkObject * object)
     if (GTK_OBJECT_CLASS(balsa_window_parent_class)->destroy)
         GTK_OBJECT_CLASS(balsa_window_parent_class)->
             destroy(GTK_OBJECT(object));
+    balsa_unregister_pixmaps();
 }
 
 
diff --git a/src/main.c b/src/main.c
index 8a1317f..44cd72a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -65,6 +65,7 @@
 #include "sendmsg-window.h"
 #include "information.h"
 #include "imap-server.h"
+#include "libbalsa-conf.h"
 
 #include "libinit_balsa/assistant_init.h"
 
@@ -1214,6 +1215,7 @@ balsa_cleanup(void)
 #if (defined(HAVE_GNOME) && !defined(GNOME_DISABLE_DEPRECATED))
     gnome_sound_shutdown();
 #endif
+    libbalsa_conf_drop_all();
 }
 
 #if HAVE_GNOME
diff --git a/src/save-restore.c b/src/save-restore.c
index 07595b9..13d1621 100644
--- a/src/save-restore.c
+++ b/src/save-restore.c
@@ -954,7 +954,7 @@ config_global_load(void)
 	/* Transition code */
 	LibBalsaSmtpServer *smtp_server;
 	LibBalsaServer *server;
-	gchar *passphrase;
+	gchar *passphrase, *hostname;
 
 	smtp_server = libbalsa_smtp_server_new();
 	libbalsa_smtp_server_set_name(smtp_server,
@@ -963,11 +963,11 @@ config_global_load(void)
 	    g_slist_prepend(NULL, smtp_server);
 	server = LIBBALSA_SERVER(smtp_server);
 
-	libbalsa_server_set_host
-	(server,
-	 libbalsa_conf_get_string_with_default("ESMTPServer=localhost:25", 
-					     &def_used),
-	 FALSE);
+        hostname = 
+            libbalsa_conf_get_string_with_default("ESMTPServer=localhost:25", 
+                                                  &def_used);
+	libbalsa_server_set_host(server, hostname, FALSE);
+        g_free(hostname);
 	libbalsa_server_set_username(server,
 		libbalsa_conf_get_string("ESMTPUser"));
 



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