* all:
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Tue, 13 Feb 2007 19:23:10 +0000 (19:23 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Tue, 13 Feb 2007 19:23:10 +0000 (19:23 +0000)
- fix some object lifetime management issues when exiting with
  errors (ie. 'modest -foobar')

pmo-trunk-r826

src/modest-main.c
src/modest-runtime.c
src/modest-singletons.c
src/modest-tny-account-store.c

index 2bd05ff..659479d 100644 (file)
@@ -103,11 +103,6 @@ main (int argc, char *argv[])
                { NULL, 0, 0, 0, NULL, NULL, NULL }
        };
 
-       if (!modest_runtime_init ()) {
-               g_printerr ("modest: cannot init runtime\n");
-               return MODEST_ERR_INIT;
-       }
-       
        context = g_option_context_new (NULL);
        g_option_context_add_main_entries (context, options, NULL);
        
@@ -120,6 +115,12 @@ main (int argc, char *argv[])
                goto cleanup;
        }
        g_option_context_free (context);
+       
+       if (!modest_runtime_init ()) {
+               g_printerr ("modest: cannot init runtime\n");
+               return MODEST_ERR_INIT;
+       }
+       
 
        account_or_default = check_account (account);
        g_free (account);
@@ -133,6 +134,11 @@ main (int argc, char *argv[])
                        retval = start_ui (account_or_default,
                                           mailto, cc, bcc, subject, body);
        } else {
+               if (!account_or_default) {
+                       g_printerr ("modest: no account has been defined yet\n");
+                       retval = MODEST_ERR_CONF;
+                       goto cleanup;
+               }
                retval = send_mail (account_or_default,
                                    mailto, cc, bcc, subject, body);
        }
index 6af5d96..c4bbdc8 100644 (file)
@@ -183,14 +183,13 @@ modest_runtime_init_ui (gint argc, gchar** argv)
 gboolean
 modest_runtime_uninit (void)
 {
-       if (!_singletons) {
-               g_printerr ("modest: modest_runtime is not initialized\n");
-               return FALSE;
+       if (_singletons) {
+               g_object_unref (G_OBJECT(_singletons));
+               _singletons = NULL;
        }
+       if (G_IS_OBJECT(_singletons)) 
+               g_warning ("BUG: _singletons is still alive\n");
        
-       g_object_unref (G_OBJECT(_singletons));
-       _singletons = NULL;
-
        return TRUE;
 }
 
index a9a04d1..1dc6a03 100644 (file)
@@ -132,7 +132,7 @@ static void
 check_object_is_dead (GObject *obj, gchar *name)
 {
        if (G_IS_OBJECT(obj))
-               g_printerr ("modest: %s is still alive\n", name);
+               g_warning ("BUG: %s is still alive\n", name);
 }
 
 static void
index f3384e0..2812c9d 100644 (file)
@@ -336,11 +336,6 @@ modest_tny_account_store_finalize (GObject *obj)
 
        g_free (priv->cache_dir);
        priv->cache_dir = NULL;
-
-       if (priv->device) {
-               g_object_unref (G_OBJECT(priv->device));
-               priv->device = NULL;
-       }
        
        if (priv->password_hash) {
                g_hash_table_destroy (priv->password_hash);
@@ -363,7 +358,12 @@ modest_tny_account_store_finalize (GObject *obj)
                camel_object_unref (CAMEL_OBJECT(priv->session));
                priv->session = NULL;
        }
-       
+
+       /* the device should be unref'ed *AFTER* the session */
+       if (priv->device) {
+               g_object_unref (G_OBJECT(priv->device));
+               priv->device = NULL;
+       }
        
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }