PATCH: anti memleak part 1



jo, subject says everything. please REVIEW the patch before
applying to CVS.. part 2 soon to follow..

hey manu, interested in nailing memleaks down in libbalsa ?

-- 
Name....: Ali Akcaagac
Status..: Student Of Computer & Economic Science
E-Mail..: mailto:ali.akcaagac@stud.fh-wilhelmshaven.de
WWW.....: http://www.fh-wilhelmshaven.de/~akcaagaa
diff -ruN balsa-cvs/src/address-book-config.c balsa/src/address-book-config.c
--- balsa-cvs/src/address-book-config.c	Thu Oct 18 16:38:15 2001
+++ balsa/src/address-book-config.c	Thu Oct 18 16:51:17 2001
@@ -94,7 +94,10 @@
     GtkWidget *bbox;
     GtkWidget *button;
     GtkWidget *page;
-    gchar *name;
+    gchar *name = NULL;
+    gchar *path = NULL;
+    gchar *host_name = NULL;
+    gchar *base_dn = NULL;
     gint num;
 
     abc = g_new0(AddressBookConfig, 1);
@@ -184,27 +187,25 @@
     name = gtk_entry_get_text(GTK_ENTRY(abc->name_entry));
     if (address_book == NULL) {
 	if (abc->create_type == LIBBALSA_TYPE_ADDRESS_BOOK_VCARD) {
-	    gchar *path =
-		gnome_file_entry_get_full_path(GNOME_FILE_ENTRY
-					       (abc->ab_specific.vcard.path), FALSE);
+	    path = gnome_file_entry_get_full_path(GNOME_FILE_ENTRY
+						  (abc->ab_specific.vcard.path),
+						  FALSE);
 	    if (path != NULL) 
 		address_book = libbalsa_address_book_vcard_new(name, path);
 	} else if (abc->create_type == LIBBALSA_TYPE_ADDRESS_BOOK_LDIF) {
-	    gchar *path =
-		gnome_file_entry_get_full_path(GNOME_FILE_ENTRY
-					       (abc->ab_specific.ldif.path), FALSE);
+	    path = gnome_file_entry_get_full_path(GNOME_FILE_ENTRY
+						  (abc->ab_specific.ldif.path),
+						  FALSE);
 	    if (path != NULL)
 		address_book = libbalsa_address_book_ldif_new(name, path);
 #ifdef ENABLE_LDAP
 	} else if (abc->create_type == LIBBALSA_TYPE_ADDRESS_BOOK_LDAP) {
-	    gchar *host_name =
-		gtk_entry_get_text(GTK_ENTRY
-				   (abc->ab_specific.ldap.host_name));
-	    gchar *base_dn =
-		gtk_entry_get_text(GTK_ENTRY
-				   (abc->ab_specific.ldap.base_dn));
-	    address_book =
-		libbalsa_address_book_ldap_new(name, host_name, base_dn);
+	    host_name = gtk_entry_get_text(GTK_ENTRY
+					   (abc->ab_specific.ldap.host_name));
+	    base_dn = gtk_entry_get_text(GTK_ENTRY
+					 (abc->ab_specific.ldap.base_dn));
+	    address_book = libbalsa_address_book_ldap_new(name, host_name,
+			   				  base_dn);
 #endif
 	} else
 	    g_assert_not_reached();
@@ -219,9 +220,9 @@
 
 	if (LIBBALSA_IS_ADDRESS_BOOK_VCARD(address_book)) {
 	    LibBalsaAddressBookVcard *vcard;
-	    gchar *path =
-		gnome_file_entry_get_full_path(GNOME_FILE_ENTRY
-					       (abc->ab_specific.vcard.path), FALSE);
+	    path = gnome_file_entry_get_full_path(GNOME_FILE_ENTRY
+						  (abc->ab_specific.vcard.path),
+						  FALSE);
 
 	    vcard = LIBBALSA_ADDRESS_BOOK_VCARD(address_book);
 	    if (path) {
@@ -230,10 +231,9 @@
 	    }
 	} else if (LIBBALSA_IS_ADDRESS_BOOK_LDIF(address_book)) {
 	    LibBalsaAddressBookLdif *ldif;
-	    gchar *path =
-		gnome_file_entry_get_full_path(GNOME_FILE_ENTRY
-					       (abc->ab_specific.ldif.path), 
-					       FALSE);
+	    path = gnome_file_entry_get_full_path(GNOME_FILE_ENTRY
+						  (abc->ab_specific.ldif.path),
+						  FALSE);
 
 	    ldif = LIBBALSA_ADDRESS_BOOK_LDIF(address_book);
 	    if (path) {
@@ -243,12 +243,10 @@
 #ifdef ENABLE_LDAP
 	} else if (LIBBALSA_IS_ADDRESS_BOOK_LDAP(address_book)) {
 	    LibBalsaAddressBookLdap *ldap;
-	    gchar *host_name =
-		gtk_entry_get_text(GTK_ENTRY
-				   (abc->ab_specific.ldap.host_name));
-	    gchar *base_dn =
-		gtk_entry_get_text(GTK_ENTRY
-				   (abc->ab_specific.ldap.base_dn));
+	    host_name =	gtk_entry_get_text(GTK_ENTRY
+					   (abc->ab_specific.ldap.host_name));
+	    base_dn = gtk_entry_get_text(GTK_ENTRY
+					 (abc->ab_specific.ldap.base_dn));
 
 	    ldap = LIBBALSA_ADDRESS_BOOK_LDAP(address_book);
 
@@ -265,7 +263,22 @@
 					 (abc->expand_aliases_button));
     }
     gtk_widget_destroy(abc->window);
-    g_free(abc);
+
+    if (abc != NULL)
+	g_free(abc);
+
+    if (name != NULL)
+	g_free(name);
+
+    if (path != NULL)
+	g_free(path);
+
+    if (host_name != NULL)
+	g_free(host_name);
+
+    if (base_dn != NULL)
+	g_free(base_dn);
+
     return address_book;
 }
 
@@ -333,9 +346,7 @@
     gtk_widget_show(label);
 #endif
 
-
     return vbox;
-
 }
 
 static GtkWidget *
@@ -380,7 +391,6 @@
     }
     gtk_widget_show_all(table);
     return table;
-
 }
 
 static GtkWidget *
diff -ruN balsa-cvs/src/address-book.c balsa/src/address-book.c
--- balsa-cvs/src/address-book.c	Thu Oct 18 16:38:15 2001
+++ balsa/src/address-book.c	Thu Oct 18 16:51:17 2001
@@ -644,9 +644,9 @@
 static void
 balsa_address_book_find(GtkWidget * group_entry, BalsaAddressBook *ab)
 {
-    gchar *entry_text;
+    gchar *entry_text = NULL;
     gpointer row;
-    gchar *new;
+    gchar *new = NULL;
     gint num;
 
     g_return_if_fail(BALSA_IS_ADDRESS_BOOK(ab));
@@ -675,6 +675,13 @@
     gtk_clist_thaw(GTK_CLIST(ab->address_clist));
     gtk_clist_select_row(GTK_CLIST(ab->address_clist), num, 
 			 LIST_COLUMN_NAME);
+
+    if (entry_text != NULL)
+	g_free(entry_text);
+
+    if (new != NULL)
+	g_free(new);
+
     return;
 }
 
@@ -730,7 +737,9 @@
 static gint
 balsa_address_book_compare_entries(GtkCList * clist, gconstpointer a, gconstpointer b)
 {
-    gchar *c1, *c2;
+    gchar *c1 = NULL;
+    gchar *c2 = NULL;
+    gint signal;
 
     GtkCListRow *row1 = (GtkCListRow *) a;
     GtkCListRow *row2 = (GtkCListRow *) b;
@@ -744,7 +753,15 @@
     if (c1 == NULL || c2 == NULL)
 	return 0;
 
-    return g_strcasecmp(c1, c2);
+    signal = g_strcasecmp(c1, c2);
+
+    if (c1 != NULL)
+	g_free(c1);
+
+    if (c2 != NULL)
+	g_free(c2);
+
+    return signal;
 }
 
 /*
@@ -763,7 +780,7 @@
     abe->ref_count = 1;
     abe->address = address;
     abe->which_multiple = which_multiple;
-    
+
     return abe;
 }
 
diff -ruN balsa-cvs/src/balsa-app.c balsa/src/balsa-app.c
--- balsa-cvs/src/balsa-app.c	Thu Oct 18 16:38:15 2001
+++ balsa/src/balsa-app.c	Thu Oct 18 16:51:17 2001
@@ -1,5 +1,4 @@
 /* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
-/* vim:set ts=4 sw=4 ai et: */
 /* Balsa E-Mail Client
  * Copyright (C) 1997-2001 Stuart Parmenter and others,
  *                         See the file AUTHORS for a list.
@@ -132,11 +131,10 @@
 gchar *
 ask_password(LibBalsaServer *server, LibBalsaMailbox *mbox)
 {
-    gchar *password;
+    gchar *password = NULL;
     
     g_return_val_if_fail(server != NULL, NULL);
 
-    password = NULL;
     if (mbox) {
         g_node_traverse(balsa_app.mailbox_nodes, G_IN_ORDER, G_TRAVERSE_LEAFS,
 		-1, check_mailbox_password, server);
@@ -188,14 +186,14 @@
 static int
 tlsinteract (char *buf, int buflen, int rwflag, void *arg)
 {
-  char *pw;
   int len;
 
-  pw = balsa_app.smtp_certificate_passphrase;
-  len = strlen (pw);
+  len = strlen (balsa_app.smtp_certificate_passphrase);
+
   if (len + 1 > buflen)
     return 0;
-  strcpy (buf, pw);
+
+  buf = balsa_app.smtp_certificate_passphrase;
   return len;
 }
 #endif
diff -ruN balsa-cvs/src/balsa-index.c balsa/src/balsa-index.c
--- balsa-cvs/src/balsa-index.c	Thu Oct 18 16:38:15 2001
+++ balsa/src/balsa-index.c	Thu Oct 18 16:51:17 2001
@@ -270,26 +270,29 @@
     GdkFont *font;
     int row_height;
 
-    
     /* status
      * priority
      * attachments
      */
     static gchar *titles[] = {
-	"#",
-	"S",
-	"A",
-	NULL,
-	NULL,
-	NULL,
-	NULL
+	N_("#"),
+	N_("S"),
+	N_("A"),
+	N_("From"),
+	N_("Subject"),
+	N_("Date"),
+	N_("Size")
     };
 
-    /* FIXME: */
-    titles[3] = _("From");
-    titles[4] = _("Subject");
-    titles[5] = _("Date");
-    titles[6] = _("Size");
+#ifdef ENABLE_NLS
+    titles[0] = _(titles[0]);
+    titles[1] = _(titles[1]);
+    titles[2] = _(titles[2]);
+    titles[3] = _(titles[3]);
+    titles[4] = _(titles[4]);
+    titles[5] = _(titles[5]);
+    titles[6] = _(titles[6]);
+#endif
 
     bindex->mailbox_node = NULL;
     adj = gtk_adjustment_new (0.0, 0.0, 10.0, 1.0, 1.0, 1.0);
@@ -301,7 +304,7 @@
     gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (bindex),
                                     GTK_POLICY_AUTOMATIC,
                                     GTK_POLICY_AUTOMATIC);
-    
+
     /* create the clist */
     bindex->ctree = GTK_CTREE (gtk_ctree_new_with_titles (7, 4, titles));
     clist = GTK_CLIST(bindex->ctree);
@@ -326,7 +329,7 @@
     gtk_clist_set_column_width(clist, 6, balsa_app.index_size_width);
     font = gtk_widget_get_style (GTK_WIDGET(clist))->font;
     row_height = font->ascent + font->descent+2;
-    
+
     if(row_height<16) /* pixmap height */
 	gtk_clist_set_row_height(clist, 16);
 
@@ -350,7 +353,7 @@
                         "unselect-all",
                         (GtkSignalFunc) unselect_all_messages, 
                         (gpointer) bindex);
-    
+
     /* we want to handle button presses to pop up context menus if
      * necessary */
     gtk_signal_connect(GTK_OBJECT(bindex->ctree),
@@ -689,12 +692,11 @@
     LibBalsaAddress *addy = NULL;
     LibBalsaMailbox* mailbox;
     gboolean append_dots;
-    
 
     g_return_if_fail(bindex != NULL);
     g_return_if_fail(message != NULL);
     mailbox = bindex->mailbox_node->mailbox;
-    
+
     if (mailbox == NULL)
 	return;
 
@@ -720,12 +722,12 @@
 
     if (addy)
 	name_str=(gchar *)libbalsa_address_get_name(addy);
-    
-    if(!name_str)		/* !addy, or addy contained no name/address */
+
+    if(!name_str) 		/* !addy, or addy contained no name/address */
 	name_str = "";
 
     text[3] = append_dots ? g_strconcat(name_str, ",...", NULL)
-	: name_str; 
+	: name_str;
 
     text[4] = (gchar*)LIBBALSA_MESSAGE_GET_SUBJECT(message);
     text[5] =
@@ -733,14 +735,18 @@
     text[6] =
 	libbalsa_message_size_to_gchar(message, balsa_app.line_length);
 
-    node = gtk_ctree_insert_node(GTK_CTREE(bindex->ctree), NULL, NULL, 
-                                 text, 2, NULL, NULL, NULL, NULL, 
+    node = gtk_ctree_insert_node(GTK_CTREE(bindex->ctree), NULL, NULL,
+                                 text, 2, NULL, NULL, NULL, NULL,
                                  FALSE, TRUE);
+
     if(append_dots) g_free(text[3]);
+
     g_free(text[5]);
     g_free(text[6]);
 
-    gtk_ctree_node_set_row_data (GTK_CTREE (bindex->ctree), node, 
+    if(name_str != NULL) g_free(name_str);
+
+    gtk_ctree_node_set_row_data (GTK_CTREE (bindex->ctree), node,
                                  (gpointer) message);
 
     balsa_index_set_col_images(bindex, node, message);
@@ -1748,7 +1754,6 @@
     LibBalsaMessage *message;
     BalsaIndex* index;
 
-
     g_return_if_fail(widget != NULL);
     g_return_if_fail(user_data != NULL);
 
@@ -1951,7 +1956,6 @@
     GPtrArray* message_array = NULL;
     GList* list = NULL;
     GtkCTree* ctree = NULL;
-    
 
     g_return_if_fail (widget != NULL);
     ctree = GTK_CTREE (widget);
@@ -2155,7 +2159,6 @@
     gtk_widget_show(scroll);
     gtk_widget_show(smenuitem);
 
-
     return menu;
 }
 
@@ -2239,7 +2242,6 @@
             balsa_index_select_previous(bindex);
     }
 
-
     libbalsa_mailbox_sync_backend(bindex->mailbox_node->mailbox);
 
     if (mbnode->mailbox == balsa_app.trash) {
diff -ruN balsa-cvs/src/balsa-message.c balsa/src/balsa-message.c
--- balsa-cvs/src/balsa-message.c	Thu Oct 18 16:38:15 2001
+++ balsa/src/balsa-message.c	Thu Oct 18 16:51:17 2001
@@ -1,5 +1,4 @@
 /* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
-/* vim:set ts=4 sw=4 ai et: */
 /* Balsa E-Mail Client
  * Copyright (C) 1997-2001 Stuart Parmenter and others,
  *                         See the file AUTHORS for a list.
diff -ruN balsa-cvs/src/mailbox-conf.c balsa/src/mailbox-conf.c
--- balsa-cvs/src/mailbox-conf.c	Thu Oct 18 16:38:15 2001
+++ balsa/src/mailbox-conf.c	Thu Oct 18 16:51:17 2001
@@ -519,7 +519,7 @@
 static void
 fill_in_imap_data(MailboxConfWindow *mcw, gchar ** name, gchar ** path)
 {
-    gchar *fos;
+    gchar *fos = NULL;
     fos =
 	gtk_entry_get_text(GTK_ENTRY(mcw->mb_data.imap.folderpath));
 
@@ -534,6 +534,9 @@
 						   (mcw->mb_data.imap.server)));
     }
     *path = g_strdup(fos);
+
+    if (fos != NULL)
+	g_free(fos);
 }
 
 /*
@@ -636,7 +639,7 @@
     update_config = mailbox->config_prefix != NULL;
 
     if (LIBBALSA_IS_MAILBOX_LOCAL(mailbox)) {
-	gchar *filename, *name;
+	gchar *filename = NULL, *name = NULL;
 
 	filename =
 	    gtk_entry_get_text(GTK_ENTRY((mcw->mb_data.local.path)));
@@ -649,6 +652,8 @@
 			      _("Rename of %s to %s failed:\n%s"),
 			      libbalsa_mailbox_local_get_path(mailbox),
 			      filename, strerror(i));
+
+	    if (filename != NULL) g_free (filename);
 	    return;
 	}
 	/* update mailbox data */
@@ -667,6 +672,9 @@
 				  ("This is a mailbox in your local directory.\n"
 				   "Change the path instead.\n"
 				   "Mailbox not Updated.\n"));
+
+		if (name != NULL) g_free (name);
+		if (filename != NULL) g_free (filename);
 		return;
 	    } else {
 		gchar *ptr = strrchr(filename, '/');
@@ -675,6 +683,8 @@
 	}
 	g_free(mailbox->name);
 	mailbox->name = g_strdup(name);
+	if (name != NULL) g_free (name);
+	if (filename != NULL) g_free (filename);
     } else if (LIBBALSA_IS_MAILBOX_POP3(mailbox)) {
 	update_pop_mailbox(mcw);
     } else if (LIBBALSA_IS_MAILBOX_IMAP(mailbox)) {
diff -ruN balsa-cvs/src/main.c balsa/src/main.c
--- balsa-cvs/src/main.c	Thu Oct 18 16:38:15 2001
+++ balsa/src/main.c	Thu Oct 18 16:51:17 2001
@@ -353,6 +353,10 @@
 	    attachment = g_strdup(ptr);
 	    add_attachment(GNOME_ICON_LIST(snd->attachments[1]), attachment,
 			   FALSE, NULL);
+
+	    g_free(ptr);
+	    g_free(delim);
+	    g_free(attachment);
 	}
     } else
 	gtk_widget_show(window);


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