* closing ModestMsgEditWindows with attachments no longer crashes modest
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Wed, 4 Jul 2007 17:28:27 +0000 (17:28 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Wed, 4 Jul 2007 17:28:27 +0000 (17:28 +0000)
  there was some confusion when TnyMimeParts were treated as gchar*s....

Fixes: NB#62598

pmo-trunk-r2576

src/maemo/modest-msg-edit-window.c

index 176dd2b..106295c 100644 (file)
@@ -1075,18 +1075,29 @@ modest_msg_edit_window_get_msg_data (ModestMsgEditWindow *edit_window)
        GList *cursor = priv->attachments;
        data->attachments = NULL;
        while (cursor) {
+               if (!(TNY_IS_MIME_PART(cursor->data))) {
+                       g_warning ("strange data in attachment list");
+                       continue;
+               }
                data->attachments = g_list_append (data->attachments,
-                                                  g_strdup ((gchar*)cursor->data));
+                                                  g_object_ref (cursor->data));
                cursor = g_list_next (cursor);
        }
        
-
        data->priority_flags = priv->priority_flags;
 
        return data;
 }
 
-/* TODO: We must duplicate this implementation for GNOME and Maemo, but that is unwise. */
+
+static void
+unref_gobject (GObject *obj, gpointer data)
+{
+       if (!G_IS_OBJECT(obj))
+               return;
+       g_object_unref (obj);
+}
+
 void 
 modest_msg_edit_window_free_msg_data (ModestMsgEditWindow *edit_window,
                                                      MsgData *data)
@@ -1108,8 +1119,8 @@ modest_msg_edit_window_free_msg_data (ModestMsgEditWindow *edit_window,
                g_object_unref (data->draft_msg);
                data->draft_msg = NULL;
        }
-
-       g_list_foreach (data->attachments, (GFunc)g_free, NULL);
+       
+       g_list_foreach (data->attachments, (GFunc)unref_gobject,  NULL);
        g_list_free (data->attachments);
        
        g_slice_free (MsgData, data);