* all:
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Thu, 15 Feb 2007 08:57:34 +0000 (08:57 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Thu, 15 Feb 2007 08:57:34 +0000 (08:57 +0000)
- add some refcount debugging support, and fix some leaks,
  comp warnings.

pmo-trunk-r832

src/modest-main.c
src/modest-runtime.h
src/modest-singletons.c
src/modest-tny-account-store.c
src/modest-tny-msg.c
src/widgets/modest-folder-view.c

index 20b8335..6dd8fa5 100644 (file)
@@ -159,39 +159,57 @@ cleanup:
 
 
 static ModestErrorCode 
-start_ui (const gchar *account, const gchar* mailto, const gchar *cc, const gchar *bcc,
+start_ui (const gchar *account_name, const gchar* mailto, const gchar *cc, const gchar *bcc,
          const gchar* subject, const gchar *body)
 {
        ModestWindow *win = NULL;
 
        if (mailto||cc||bcc||subject||body) {           
                gchar *from;
-               TnyMsg *msg;
-               TnyFolder *folder;
-               if (!account) {
-                       g_printerr ("modest: no valid account provided, nor is default one available\n");
+               TnyMsg     *msg;
+               TnyFolder  *folder;
+               TnyAccount *account;
+               
+               if (!account_name) {
+                       g_printerr ("modest: no valid account provided, "
+                                   "nor is default one available\n");
                        return MODEST_ERR_PARAM;
                }
-               from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(), account);
+               from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
+                                                          account_name);
                msg  = modest_tny_msg_new (mailto,from,cc,bcc,subject,body,NULL);
                if (!msg) {
                        g_printerr ("modest: failed to create message\n");
                        g_free (from);
                        return MODEST_ERR_SEND;
                }
+
+               account = modest_tny_account_store_get_tny_account_by_account (
+                       modest_runtime_get_account_store(), account_name,
+                       TNY_ACCOUNT_TYPE_TRANSPORT);
+               if (!account) {
+                       g_printerr ("modest: failed to get tny account folder\n");
+                       g_free (from);
+                       g_object_unref (G_OBJECT(msg));
+                       return MODEST_ERR_SEND;
+               }
+               
                folder = modest_tny_account_get_special_folder (account,
                                                                TNY_FOLDER_TYPE_DRAFTS);
                if (!folder) {
                        g_printerr ("modest: failed to find Drafts folder\n");
                        g_free (from);
                        g_object_unref (G_OBJECT(msg));
+                       g_object_unref (G_OBJECT(account));
                        return MODEST_ERR_SEND;
                }
                tny_folder_add_msg (folder, msg, NULL); /* FIXME: check err */
 
-               win = modest_msg_edit_window_new (msg, account);
+               win = modest_msg_edit_window_new (msg, account_name);
                
                g_object_unref (G_OBJECT(msg));
+               g_object_unref (G_OBJECT(account));
+               g_object_unref (G_OBJECT(folder));
                g_free (from);
        } else 
                win = modest_main_window_new ();
index 2319ff7..e4f91e8 100644 (file)
@@ -49,7 +49,7 @@ typedef enum {
        MODEST_RUNTIME_DEBUG_LOG_ACTIONS           = 1 << 1, /* not in use atm */
        MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS         = 1 << 2, /* for g_type_init */
        MODEST_RUNTIME_DEBUG_DEBUG_SIGNALS         = 1 << 3, /* for g_type_init */
-       MODEST_RUNTIME_DEBUG_FACTORY_SETTINGS      = 1 << 4, /* reset to factory defaults */
+       MODEST_RUNTIME_DEBUG_FACTORY_SETTINGS      = 1 << 4  /* reset to factory defaults */
 } ModestRuntimeDebugFlags;
 
 /**
@@ -97,9 +97,9 @@ gboolean modest_runtime_uninit (void);
  * - "abort-on-warning": abort the program when a gtk/glib/.. warning occurs.
  * useful when running in debugger
  * - "log-actions": log user actions (not in use atm)
- * - "track-object": track the use of (g)objects in the program. this option influences
+ * - "debug-objects": track the use of (g)objects in the program. this option influences
  *  g_type_init_with_debug_flags
- *  - "track-signals": track the use of (g)signals in the program. this option influences
+ *  - "debug-signals": track the use of (g)signals in the program. this option influences
  *  g_type_init_with_debug_flags
  * if you would want to track signals and log actions, you could do something like:
  *  MODEST_DEBUG="log-actions:track-signals" ./modest
index 541f4be..61d0b08 100644 (file)
@@ -28,6 +28,7 @@
  */
 
 #include "modest-singletons.h"
+#include "modest-runtime.h"
 
 /* 'private'/'protected' functions */
 static void modest_singletons_class_init (ModestSingletonsClass *klass);
@@ -148,54 +149,62 @@ static void
 check_object_is_dead (GObject *obj, gchar *name)
 {
        if (G_IS_OBJECT(obj))
-               g_warning ("BUG: %s is still alive\n", name);
+               g_warning ("BUG: %s still has %d ref(s)\n", name, obj->ref_count);
 }
 
 static void
 modest_singletons_finalize (GObject *obj)
 {
        ModestSingletonsPrivate *priv;
+       gboolean debug = modest_runtime_get_debug_flags() & MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS;
+               
        priv = MODEST_SINGLETONS_GET_PRIVATE(obj);
 
        if (priv->account_store) {
                g_object_unref (G_OBJECT(priv->account_store));
-               check_object_is_dead ((GObject*)priv->account_store,
-                                     "priv->account_store");
+               if (debug)
+                       check_object_is_dead ((GObject*)priv->account_store,
+                                             "priv->account_store");
                priv->account_store = NULL;
        }
 
        if (priv->account_mgr) {
                g_object_unref (G_OBJECT(priv->account_mgr));
-               check_object_is_dead ((GObject*)priv->account_mgr,
-                                     "priv->account_mgr");
+               if (debug)
+                       check_object_is_dead ((GObject*)priv->account_mgr,
+                                             "priv->account_mgr");
                priv->account_mgr = NULL;
        }
 
        if (priv->conf) {
                g_object_unref (G_OBJECT(priv->conf));
-               check_object_is_dead ((GObject*)priv->conf,
-                                     "priv->conf");
+               if (debug)
+                       check_object_is_dead ((GObject*)priv->conf,
+                                             "priv->conf");
                priv->conf = NULL;
        }
 
        if (priv->cache_mgr) {
                g_object_unref (G_OBJECT(priv->cache_mgr));
-               check_object_is_dead ((GObject*)priv->cache_mgr,
-                                     "priv->cache_mgr");
+               if (debug)
+                       check_object_is_dead ((GObject*)priv->cache_mgr,
+                                             "priv->cache_mgr");
                priv->cache_mgr = NULL;
        }
 
        if (priv->device) {
                g_object_unref (G_OBJECT(priv->device));
-               check_object_is_dead ((GObject*)priv->cache_mgr,
-                                     "priv->device");
+               if (debug)
+                       check_object_is_dead ((GObject*)priv->cache_mgr,
+                                             "priv->device");
                priv->device = NULL;
        }
 
        if (priv->platform_fact) {
                g_object_unref (G_OBJECT(priv->platform_fact));
-               check_object_is_dead ((GObject*)priv->cache_mgr,
-                                     "priv->platform_fact");
+               if (debug)
+                       check_object_is_dead ((GObject*)priv->cache_mgr,
+                                             "priv->platform_fact");
                priv->platform_fact = NULL;
        }
 
index 3d518cd..9868a51 100644 (file)
@@ -177,11 +177,14 @@ static void
 account_list_free (GSList *accounts)
 {
        GSList *cursor = accounts;
+       gboolean debug = modest_runtime_get_debug_flags() & MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS;
+
        while (cursor) {
                g_object_unref (G_OBJECT(cursor->data));
-/*             if (G_IS_OBJECT(cursor->data)) */
-/*                     g_warning ("BUG: account %s still holds refs", */
-/*                                tny_account_get_id (TNY_ACCOUNT(cursor->data))); */
+               if (debug && G_IS_OBJECT(cursor->data))
+                       g_warning ("BUG: account %s still holds %d ref(s)",
+                                  tny_account_get_id (TNY_ACCOUNT(cursor->data)),
+                                  G_OBJECT(cursor->data)->ref_count);
                cursor = cursor->next;
        }
        g_slist_free (accounts);
@@ -335,6 +338,8 @@ modest_tny_account_store_finalize (GObject *obj)
 {
        ModestTnyAccountStore *self        = MODEST_TNY_ACCOUNT_STORE(obj);
        ModestTnyAccountStorePrivate *priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
+       
+       gboolean debug = modest_runtime_get_debug_flags() & MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS;
 
        g_free (priv->cache_dir);
        priv->cache_dir = NULL;
@@ -363,6 +368,9 @@ modest_tny_account_store_finalize (GObject *obj)
 
        if (priv->session) {
                camel_object_unref (CAMEL_OBJECT(priv->session));
+               if (debug && CAMEL_IS_OBJECT(priv->session))
+                               g_warning ("BUG: TnyCamelSession still holds %d ref(s)",
+                                  CAMEL_OBJECT(priv->session)->ref_count);     
                priv->session = NULL;
        }
        
@@ -447,15 +455,19 @@ get_accounts  (TnyAccountStore *self, TnyList *list, TnyAccountType type)
                /* only return enabled accounts */
                if (modest_account_mgr_get_enabled(priv->account_mgr, account_name)) {
                        TnyAccount *tny_account = 
-                               modest_tny_account_new_from_account (priv->account_mgr, account_name,
-                                                                    type, priv->session, get_password,
+                               modest_tny_account_new_from_account (priv->account_mgr,
+                                                                    account_name,
+                                                                    type, priv->session,
+                                                                    get_password,
                                                                     forget_password);
                        if (tny_account) { /* something went wrong */
-                               g_object_set_data (G_OBJECT(tny_account), "account_store", (gpointer)self);
+                               g_object_set_data (G_OBJECT(tny_account), "account_store",
+                                                  (gpointer)self);
                                tny_list_prepend (list, G_OBJECT(tny_account));
                                accounts = g_slist_append (accounts, tny_account); /* cache it */
                        } else
-                               g_printerr ("modest: failed to create account for %s\n", account_name);
+                               g_printerr ("modest: failed to create account for %s\n",
+                                           account_name);
                }
                g_free (account_name);
        }
@@ -485,8 +497,10 @@ modest_tny_account_store_get_accounts  (TnyAccountStore *self, TnyList *list,
        priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
        
        if (request_type == TNY_ACCOUNT_STORE_BOTH) {
-               modest_tny_account_store_get_accounts (self, list, TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
-               modest_tny_account_store_get_accounts (self, list, TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS);
+               modest_tny_account_store_get_accounts (self, list,
+                                                      TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
+               modest_tny_account_store_get_accounts (self, list,
+                                                      TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS);
                return;
        }
        
@@ -500,7 +514,8 @@ modest_tny_account_store_get_accounts  (TnyAccountStore *self, TnyList *list,
        } else if (request_type == TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS) {
 
                if (!priv->transport_accounts)
-                       priv->transport_accounts = get_accounts (self, list, TNY_ACCOUNT_TYPE_TRANSPORT);
+                       priv->transport_accounts =
+                               get_accounts (self, list, TNY_ACCOUNT_TYPE_TRANSPORT);
                else
                        get_cached_accounts (self, list, TNY_ACCOUNT_TYPE_TRANSPORT);
        } else {
index 4c5b67d..71414f8 100644 (file)
 #include <tny-gtk-text-buffer-stream.h>
 #include <tny-simple-list.h>
 #include <tny-folder.h>
-#include <modest-tny-platform-factory.h>
+#include <modest-runtime.h>
 #include <tny-camel-stream.h>
 #include <camel/camel-stream-mem.h>
 
-
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif /*HAVE_CONFIG_H */
index b333407..2c2aa73 100644 (file)
@@ -276,6 +276,9 @@ text_cell_data  (GtkTreeViewColumn *column,  GtkCellRenderer *renderer,
                g_object_set (rendobj,"text", fname, "weight", 400, NULL);
                
        g_free (fname);
+       if (folder)
+               g_object_unref (G_OBJECT(folder));
+       
 }
 
 
@@ -622,9 +625,12 @@ update_model (ModestFolderView *self, ModestTnyAccountStore *account_store)
                /* Set new model */
                gtk_tree_view_set_model (GTK_TREE_VIEW(self), sortable);
                expand_root_items (self); /* expand all account folders */
+               g_object_unref (account_list);
        }
        
-       g_object_unref (model);
+       //if (model)
+       //      g_object_unref (model);
+               
        return TRUE;
 }
 
@@ -833,6 +839,12 @@ cmp_rows (GtkTreeModel *tree_model, GtkTreeIter *iter1, GtkTreeIter *iter2,
                        cmp = modest_text_utils_utf8_strcmp (name1, name2, TRUE);
        } else 
                cmp = modest_text_utils_utf8_strcmp (name1, name2, TRUE);
+
+       
+       if (folder1)
+               g_object_unref(G_OBJECT(folder1));
+       if (folder2)
+               g_object_unref(G_OBJECT(folder2));
        
        g_free (name1);
        g_free (name2);
@@ -1003,6 +1015,12 @@ on_drag_data_received (GtkWidget *widget,
                        success = TRUE;
                }
                gtk_tree_row_reference_free (source_row_reference);
+               
+               if (folder)
+                       g_object_unref (G_OBJECT(folder));
+               if (parent_folder)
+                       g_object_unref (G_OBJECT(parent_folder));
+               
        }
  out:
        gtk_tree_path_free (child_dest_row);