[balsa] Plug leak, and use an array in place of a string



commit 9171c1f600be36aea8c41764850e4fedd92d8e33
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Thu Sep 24 15:55:12 2009 -0400

    Plug leak, and use an array in place of a string

 ChangeLog       |    6 ++++++
 src/balsa-app.c |   32 ++++++++++++++------------------
 2 files changed, 20 insertions(+), 18 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 8155501..2b49100 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2009-09-24  Peter Bloomfield
 
+	* src/balsa-app.c (append_url_if_open): use a GPtrArray to
+	collect URLs instead of a GString;
+	(open_mailboxes_idle_cb): ditto; do not leak urls.
+
+2009-09-24  Peter Bloomfield
+
 	* src/balsa-app.c (open_mailboxes_idle_cb): do not open most
 	recent mailbox if no mailboxes were open.
 
diff --git a/src/balsa-app.c b/src/balsa-app.c
index 480e7b2..e172497 100644
--- a/src/balsa-app.c
+++ b/src/balsa-app.c
@@ -509,13 +509,10 @@ update_timer(gboolean update, guint minutes)
 
 static void
 append_url_if_open(const gchar * url, LibBalsaMailboxView * view,
-                   GString * str)
+                   GPtrArray * array)
 {
-    if (view->open) {
-        if (str->len)
-            g_string_append_c(str, ';');
-        g_string_append(str, url);
-    }
+    if (view->open)
+        g_ptr_array_add(array, g_strdup(url));
 }
 
 static void
@@ -559,28 +556,27 @@ open_mailboxes_idle_cb(gchar ** urls)
     gdk_threads_enter();
 
     if (!urls) {
-        GString *str;
+        GPtrArray *array;
 
         if (!libbalsa_mailbox_view_table) {
             gdk_threads_leave();
             return FALSE;
         }
 
-        str = g_string_new(NULL);
+        array = g_ptr_array_new();
         g_hash_table_foreach(libbalsa_mailbox_view_table,
-                             (GHFunc) append_url_if_open, str);
-        urls = g_strsplit(str->str, ";", 0);
-        g_string_free(str, TRUE);
+                             (GHFunc) append_url_if_open, array);
+        g_ptr_array_add(array, NULL);
+        urls = (gchar **) g_ptr_array_free(array, FALSE);
     }
 
-    if (urls && *urls) {
-        open_mailbox_by_url(balsa_app.current_mailbox_url);
+    if (urls) {
+        if (*urls) {
+            open_mailbox_by_url(balsa_app.current_mailbox_url);
 
-        for (tmp = urls; *tmp; ++tmp)
-{
-g_print("%s url \"%s\"\n", __func__, *tmp);
-            open_mailbox_by_url(*tmp);
-}
+            for (tmp = urls; *tmp; ++tmp)
+                open_mailbox_by_url(*tmp);
+        }
 
         g_strfreev(urls);
     }



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