* don't use gobjects that might be dead
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Fri, 27 Apr 2007 12:30:16 +0000 (12:30 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Fri, 27 Apr 2007 12:30:16 +0000 (12:30 +0000)
pmo-trunk-r1693

src/modest-mail-operation-queue.c
src/modest-runtime.c
src/modest-runtime.h
src/modest-singletons.c
src/modest-tny-account-store.c
src/widgets/modest-header-view.c

index 26c2888..4f8270e 100644 (file)
@@ -203,8 +203,8 @@ modest_mail_operation_queue_remove (ModestMailOperationQueue *self,
                       mail_op, MODEST_MAIL_OPERATION_QUEUE_OPERATION_REMOVED);
 
        /* Free object */
+       modest_runtime_verify_object_last_ref (mail_op, "");
        g_object_unref (G_OBJECT (mail_op));
-       modest_runtime_verify_object_death (mail_op, "");
 }
 
 
index f67db37..66a206d 100644 (file)
@@ -77,8 +77,8 @@ modest_runtime_uninit (void)
                return TRUE;    /* uninit maybe called if runtime_init failed */
        
        g_return_val_if_fail (MODEST_IS_SINGLETONS(_singletons), FALSE);
+       modest_runtime_verify_object_last_ref(_singletons,"");
        g_object_unref(G_OBJECT(_singletons));
-       modest_runtime_verify_object_death(_singletons,"");
        _singletons = NULL;
                
        return TRUE;
index 8fef29b..6d5f821 100644 (file)
@@ -206,22 +206,24 @@ ModestTnySendQueue* modest_runtime_get_send_queue        (TnyTransportAccount *a
 ModestWindowMgr* modest_runtime_get_window_mgr (void);
 
 /**
- * modest_runtime_verify_object_death
+ * modest_runtime_verify_object_last_ref
  * @OBJ: some (GObject) ptr
  * @NAME: name of @OBJ
  * 
- * macro to check whether @obj is 'dead', ie, it is no longer a valid GObject. If
+ * macro to check whether @obj holds only one more ref (ie. after the
+ * next unref it will die)
+ * 
  * not, a g_warning will be issued on stderr. NOTE: this is only active
  * when MODEST_DEBUG contains "debug-objects".
  *
  ***/
-#define modest_runtime_verify_object_death(OBJ,name)                   \
-       do {                                                            \
-               if (modest_runtime_get_debug_flags() & MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS) \
-                       if (G_IS_OBJECT(OBJ))                           \
-                               g_warning ("%s:%d: %s ("        \
-                                          #OBJ ") still holds a ref count of %d", \
-                                          __FILE__,__LINE__,name, G_OBJECT(OBJ)->ref_count); \
+#define modest_runtime_verify_object_last_ref(OBJ,name)                                                       \
+       do {                                                                                           \
+               if (modest_runtime_get_debug_flags() & MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS)             \
+                       if (G_IS_OBJECT(OBJ) && G_OBJECT(OBJ)->ref_count != 1)                         \
+                               g_warning ("%s:%d: %s ("                                               \
+                                          #OBJ ") still holds a ref count of %d",                     \
+                                          __FILE__,__LINE__,name, G_OBJECT(OBJ)->ref_count);          \
        } while (0)
 
 
index 44653fe..9c0ede2 100644 (file)
@@ -160,50 +160,50 @@ modest_singletons_finalize (GObject *obj)
        priv = MODEST_SINGLETONS_GET_PRIVATE(obj);
 
        if (priv->account_store) {
+               modest_runtime_verify_object_last_ref(priv->account_store,"");
                g_object_unref (G_OBJECT(priv->account_store));
-               modest_runtime_verify_object_death(priv->account_store,"");
                priv->account_store = NULL;
        }
 
        if (priv->account_mgr) {
+               modest_runtime_verify_object_last_ref(priv->account_mgr,"");
                g_object_unref (G_OBJECT(priv->account_mgr));
-               modest_runtime_verify_object_death(priv->account_mgr,"");
                priv->account_mgr = NULL;
        }
 
        if (priv->conf) {
+               modest_runtime_verify_object_last_ref(priv->conf,"");
                g_object_unref (G_OBJECT(priv->conf));
-               modest_runtime_verify_object_death(priv->conf,"");
                priv->conf = NULL;
        }
 
        if (priv->cache_mgr) {
+               modest_runtime_verify_object_last_ref(priv->cache_mgr,"");
                g_object_unref (G_OBJECT(priv->cache_mgr));
-               modest_runtime_verify_object_death(priv->cache_mgr,"");
                priv->cache_mgr = NULL;
        }
 
        if (priv->device) {
+               modest_runtime_verify_object_last_ref(priv->device,"");
                g_object_unref (G_OBJECT(priv->device));
-               modest_runtime_verify_object_death(priv->device,"");
                priv->device = NULL;
        }
 
        if (priv->platform_fact) {
+               modest_runtime_verify_object_last_ref(priv->platform_fact,"");
                g_object_unref (G_OBJECT(priv->platform_fact));
-               modest_runtime_verify_object_death(priv->platform_fact,"");
                priv->platform_fact = NULL;
        }
 
        if (priv->mail_op_queue) {
+               modest_runtime_verify_object_last_ref(priv->mail_op_queue,"");
                g_object_unref (G_OBJECT(priv->mail_op_queue));
-               modest_runtime_verify_object_death(priv->mail_op_queue,"");
                priv->mail_op_queue = NULL;
        }
        
        if (priv->window_mgr) {
+               modest_runtime_verify_object_last_ref(priv->window_mgr,"");
                g_object_unref (G_OBJECT(priv->window_mgr));
-               modest_runtime_verify_object_death(priv->window_mgr,"");
                priv->window_mgr = NULL;
        }
 
index 8eac8c8..14be515 100644 (file)
@@ -186,14 +186,11 @@ account_list_free (GSList *accounts)
        GSList *cursor = accounts;
 
        while (cursor) {
-               /* TODO: This uses cursor->data after causing it to be freed,
-                * as valgrind shows.
-                * It's not clear what is being attempted here. murrayc */
-               g_object_unref (G_OBJECT(cursor->data));
                if (G_IS_OBJECT(cursor->data)) { /* check twice... */
                        const gchar *id = tny_account_get_id(TNY_ACCOUNT(cursor->data));
-                       modest_runtime_verify_object_death(cursor->data,id);
+                       modest_runtime_verify_object_last_ref(cursor->data,id);
                }                       
+               g_object_unref (G_OBJECT(cursor->data));
                cursor = cursor->next;
        }
        g_slist_free (accounts);
@@ -383,7 +380,6 @@ modest_tny_account_store_finalize (GObject *obj)
 
        if (priv->session) {
                camel_object_unref (CAMEL_OBJECT(priv->session));
-               modest_runtime_verify_object_death(priv->session, "");
                priv->session = NULL;
        }
        
index c2265ba..c49b964 100644 (file)
@@ -695,9 +695,6 @@ modest_header_view_set_model (GtkTreeView *header_view, GtkTreeModel *model)
 
                /* Set new model */
                gtk_tree_view_set_model (header_view, model);
-
-               modest_runtime_verify_object_death (old_model, "");
-               modest_runtime_verify_object_death (old_model_sort, "");
        } else
                gtk_tree_view_set_model (header_view, model);