* fix some memory leaks (valgrind helps)
[modest] / src / modest-tny-account-store.c
index fd792c5..8ef3743 100644 (file)
@@ -344,7 +344,7 @@ on_account_removed (ModestAccountMgr *acc_mgr,
        
        /* Clear the account cache */
        store_account = modest_tny_account_store_get_tny_account_by  (self, 
-                                                                     MODEST_TNY_ACCOUNT_STORE_QUERY_NAME, 
+                                                                     MODEST_TNY_ACCOUNT_STORE_QUERY_ID, 
                                                                      account);
        if (store_account) {
                tny_store_account_delete_cache (TNY_STORE_ACCOUNT (store_account));
@@ -600,17 +600,14 @@ modest_tny_account_store_new (ModestAccountMgr *account_mgr, TnyDevice *device)
        priv->device = g_object_ref (device);
        
        priv->session = tny_session_camel_new (TNY_ACCOUNT_STORE(obj));
+       if (!priv->session) {
+               g_warning ("failed to get TnySessionCamel");
+               return NULL;
+       }
        
        tny_session_camel_set_ui_locker (priv->session,  tny_gtk_lockable_new ());
-       /* FIXME: unref this in the end? */
        tny_session_camel_set_async_connecting (priv->session, TRUE);
-       
-       /* force a cache fill... ugly */
-       /* list = TNY_LIST(tny_simple_list_new()); */
-/*     tny_account_store_get_accounts (TNY_ACCOUNT_STORE(obj), list, */
-/*                                     TNY_ACCOUNT_STORE_BOTH); */
-/*     g_object_unref(list); */
-       
+               
        /* Connect signals */
        g_signal_connect (G_OBJECT(account_mgr), "account_changed",
                                       G_CALLBACK (on_account_changed), obj);
@@ -790,7 +787,7 @@ get_server_accounts  (TnyAccountStore *self, TnyList *list, TnyAccountType type)
                                                TnyAccount * tny_account = NULL;
                                                /* Add the account: */
                                                tny_account = modest_tny_account_new_from_server_account_name (
-                                                       priv->account_mgr, transport_account_name);
+                                                       priv->account_mgr, priv->session, transport_account_name);
                                                if (tny_account) {
                                                        g_object_set_data (G_OBJECT(tny_account), "account_store",
                                                                           (gpointer)self);
@@ -1167,9 +1164,6 @@ modest_tny_account_store_get_tny_account_by (ModestTnyAccountStore *self,
                case MODEST_TNY_ACCOUNT_STORE_QUERY_ID:
                        val = tny_account_get_id (TNY_ACCOUNT(cursor->data));
                        break;
-               case MODEST_TNY_ACCOUNT_STORE_QUERY_NAME:
-                       val = modest_tny_account_get_parent_modest_account_name_for_server_account (TNY_ACCOUNT(cursor->data));
-                       break;
                case MODEST_TNY_ACCOUNT_STORE_QUERY_URL:
                        val = tny_account_get_url_string (TNY_ACCOUNT(cursor->data));
                        break;
@@ -1193,9 +1187,6 @@ modest_tny_account_store_get_tny_account_by (ModestTnyAccountStore *self,
                case MODEST_TNY_ACCOUNT_STORE_QUERY_ID:
                        val = tny_account_get_id (TNY_ACCOUNT(cursor->data));
                        break;
-               case MODEST_TNY_ACCOUNT_STORE_QUERY_NAME:
-                       val = tny_account_get_name (TNY_ACCOUNT(cursor->data));
-                       break;
                case MODEST_TNY_ACCOUNT_STORE_QUERY_URL:
                        val = tny_account_get_url_string (TNY_ACCOUNT(cursor->data));
                        break;
@@ -1215,6 +1206,17 @@ modest_tny_account_store_get_tny_account_by (ModestTnyAccountStore *self,
  end:
        if (account)
                g_object_ref (G_OBJECT(account));
+       else {
+               /* Warn if nothing was found. This is generally unusual. */
+               switch (type) {
+               case MODEST_TNY_ACCOUNT_STORE_QUERY_ID:
+                       g_warning("%s: Failed to find account with ID=%s\n", __FUNCTION__, str);
+                       break;
+               case MODEST_TNY_ACCOUNT_STORE_QUERY_URL:
+                       g_warning("%s: Failed to find account with URL=%s\n", __FUNCTION__, str);
+                       break;
+               }
+       }
        
        return account;
 }
@@ -1264,12 +1266,14 @@ modest_tny_account_store_get_server_account (ModestTnyAccountStore *self,
                g_printerr ("modest: could not get an id for account %s\n",
                            account_name);
        else    
-               account = modest_tny_account_store_get_tny_account_by (self, MODEST_TNY_ACCOUNT_STORE_QUERY_ID, id);
+               account = modest_tny_account_store_get_tny_account_by (self, 
+                                                                      MODEST_TNY_ACCOUNT_STORE_QUERY_ID, id);
 
        if (!account)
                g_printerr ("modest: could not get tny %s account for %s (id=%s)\n",
                            type == TNY_ACCOUNT_TYPE_STORE ? "store" : "transport",
                            account_name, id ? id : "<none>");
+       g_free (id);
 
        return account; 
 }