Fixed a leak in modest_mail_operation_get_msgs_full()
[modest] / src / modest-mail-operation.c
index 27f62c4..151f2d8 100644 (file)
@@ -2161,10 +2161,15 @@ get_msg_async_cb (TnyFolder *folder,
        /* Check errors */
        if (canceled || err) {
                priv->status = MODEST_MAIL_OPERATION_STATUS_FINISHED_WITH_ERRORS;
-               if (!priv->error)
+               if (err) {
+                       priv->error = g_error_copy ((const GError *) err);
+                       priv->error->domain = MODEST_MAIL_OPERATION_ERROR;
+               }
+               if (!priv->error) {
                        g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR,
                                     MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
                                     err->message);
+               }
        } else if (finished && priv->status == MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS) {
                /* Set the success status before calling the user callback */
                priv->status = MODEST_MAIL_OPERATION_STATUS_SUCCESS;
@@ -2235,8 +2240,8 @@ modest_mail_operation_get_msgs_full (ModestMailOperation *self,
 
        /* Get account and set it into mail_operation */
        if (tny_list_get_length (header_list) >= 1) {
-               iter = tny_list_create_iterator (header_list);
-               TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
+               TnyIterator *iterator = tny_list_create_iterator (header_list);
+               TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iterator));
                if (header) {
                        TnyFolder *folder = tny_header_get_folder (header);
                        if (folder) {           
@@ -2245,11 +2250,7 @@ modest_mail_operation_get_msgs_full (ModestMailOperation *self,
                        }
                        g_object_unref (header);
                }
-
-               if (tny_list_get_length (header_list) == 1) {
-                       g_object_unref (iter);
-                       iter = NULL;
-               }
+               g_object_unref (iterator);
        }
 
        msg_list_size = compute_message_list_size (header_list);