Make procmsg_msginfo_free() zero out pointers to freed memory.
[claws.git] / src / folder.c
index 081c4b1e2106956d42100394c68073a9e87cc5b0..f2237ecce7c960980c0cecc4c857f1b38bc86f82 100644 (file)
@@ -302,7 +302,7 @@ void folder_set_xml(Folder *folder, XMLTag *tag)
 
                        account = account_find_from_id(atoi(attr->value));
                        if (!account)
-                               g_warning("account_id: %s not found\n", attr->value);
+                               g_warning("account_id: %s not found", attr->value);
                        else {
                                folder->account = account;
                                account->folder = folder;
@@ -389,8 +389,8 @@ FolderItem *folder_item_new(Folder *folder, const gchar *name, const gchar *path
        item->data = NULL;
        item->parent_stype = -1;
 
-       item->sort_key = SORT_BY_DATE;
-       item->sort_type = SORT_ASCENDING;
+       item->sort_key = prefs_common.default_sort_key;
+       item->sort_type = prefs_common.default_sort_type;
 
        item->prefs = folder_item_prefs_new();
 
@@ -637,7 +637,7 @@ void folder_item_set_xml(Folder *folder, FolderItem *item, XMLTag *tag)
 
                        account = account_find_from_id(atoi(attr->value));
                        if (!account)
-                               g_warning("account_id: %s not found\n", attr->value);
+                               g_warning("account_id: %s not found", attr->value);
                        else
                                item->account = account;
                } else if (!strcmp(attr->name, "apply_sub")) {
@@ -833,7 +833,7 @@ gint folder_read_list(void)
 
        xmlnode = node->data;
        if (strcmp2(xmlnode->tag->tag, "folderlist") != 0) {
-               g_warning("wrong folder list\n");
+               g_warning("wrong folder list");
                xml_free_tree(node);
                return -1;
        }
@@ -874,7 +874,7 @@ void folder_write_list(void)
 
        if (xml_file_put_xml_decl(pfile->fp) < 0) {
                prefs_file_close_revert(pfile);
-               g_warning("failed to start write folder list.\n");
+               g_warning("failed to start write folder list.");
                return;         
        }
        tag = xml_tag_new("folderlist");
@@ -900,9 +900,9 @@ void folder_write_list(void)
 
        if (xml_write_tree(rootnode, pfile->fp) < 0) {
                prefs_file_close_revert(pfile);
-               g_warning("failed to write folder list.\n");
+               g_warning("failed to write folder list.");
        } else if (prefs_file_close(pfile) < 0) {
-               g_warning("failed to write folder list.\n");
+               g_warning("failed to write folder list.");
        }
        xml_free_tree(rootnode);
 }
@@ -1848,7 +1848,7 @@ void folder_set_missing_folders(void)
                        continue;
 
                if (folder->klass->create_tree(folder) < 0) {
-                       g_warning("%s: can't create the folder tree.\n",
+                       g_warning("%s: can't create the folder tree.",
                                  LOCAL_FOLDER(folder)->rootpath);
                        continue;
                }
@@ -1981,8 +1981,9 @@ static gint folder_item_syncronize_flags(FolderItem *item)
        
        ret = syncronize_flags(item, msglist);
 
-       for (cur = msglist; cur != NULL; cur = g_slist_next(cur))
-               procmsg_msginfo_free((MsgInfo *) cur->data);
+       for (cur = msglist; cur != NULL; cur = g_slist_next(cur)) {
+               procmsg_msginfo_free((MsgInfo **)&(cur->data));
+       }
        
        g_slist_free(msglist);
 
@@ -2062,7 +2063,7 @@ gint folder_item_close(FolderItem *item)
                        msginfo = (MsgInfo *) cur->data;
                        if (MSG_IS_NEW(msginfo->flags))
                                procmsg_msginfo_unset_flags(msginfo, MSG_NEW, 0);
-                       procmsg_msginfo_free(msginfo);
+                       procmsg_msginfo_free(&msginfo);
                }
                g_slist_free(mlist);
                folder_item_update_thaw();
@@ -2283,7 +2284,7 @@ gint folder_item_scan_full(FolderItem *item, gboolean filtering)
                        if (msginfo && folder->klass->is_msg_changed && folder->klass->is_msg_changed(folder, item, msginfo)) {
                                msgcache_remove_msg(item->cache, msginfo->msgnum);
                                new_list = g_slist_prepend(new_list, GINT_TO_POINTER(msginfo->msgnum));
-                               procmsg_msginfo_free(msginfo);
+                               procmsg_msginfo_free(&msginfo);
 
                                debug_print("Remembering message %d to update...\n", folder_cur_num);
                        } else if (msginfo) {
@@ -2318,7 +2319,7 @@ gint folder_item_scan_full(FolderItem *item, gboolean filtering)
        }
        
        for(cache_list_cur = cache_list; cache_list_cur != NULL; cache_list_cur = g_slist_next(cache_list_cur))
-               procmsg_msginfo_free((MsgInfo *) cache_list_cur->data);
+               procmsg_msginfo_free((MsgInfo **)&(cache_list_cur->data));
 
        g_slist_free(cache_list);
        g_slist_free(folder_list);
@@ -2373,7 +2374,7 @@ gint folder_item_scan_full(FolderItem *item, gboolean filtering)
                        if (to_filter != NULL) {
                                for (elem = to_filter; elem; elem = g_slist_next(elem)) {
                                        MsgInfo *msginfo = (MsgInfo *)elem->data;
-                                       procmsg_msginfo_free(msginfo);
+                                       procmsg_msginfo_free(&msginfo);
                                }
                                g_slist_free(to_filter);
                        }
@@ -2450,7 +2451,7 @@ gint folder_item_scan_full(FolderItem *item, gboolean filtering)
 
                totalcnt++;
 
-               procmsg_msginfo_free(msginfo);
+               procmsg_msginfo_free(&msginfo);
        }
        folder_item_set_batch(item, FALSE);
        g_slist_free(exists_list);
@@ -2900,7 +2901,7 @@ gchar *folder_item_fetch_msg(FolderItem *item, gint num)
                                procmsg_msginfo_set_flags(msginfo, 0, MSG_SCANNED);
                        }
                }
-               procmsg_msginfo_free(msginfo);
+               procmsg_msginfo_free(&msginfo);
        }
 
        return msgfile;
@@ -2947,7 +2948,7 @@ gchar *folder_item_fetch_msg_full(FolderItem *item, gint num, gboolean headers,
                                procmsg_msginfo_set_flags(msginfo, 0, MSG_SCANNED);
                        }
                }
-               procmsg_msginfo_free(msginfo);
+               procmsg_msginfo_free(&msginfo);
        }
 
        return msgfile;
@@ -2994,7 +2995,7 @@ static gint folder_item_get_msg_num_by_file(FolderItem *dest, const gchar *file)
                remove_space(hentry[0].body);
                if ((msginfo = msgcache_get_msg_by_id(dest->cache, hentry[0].body)) != NULL) {
                        msgnum = msginfo->msgnum;
-                       procmsg_msginfo_free(msginfo);
+                       procmsg_msginfo_free(&msginfo);
 
                        debug_print("found message as uid %d\n", msgnum);
                }
@@ -3219,10 +3220,10 @@ gint folder_item_add_msgs(FolderItem *dest, GSList *file_list,
                        if (!folderscan && 
                            ((newmsginfo = get_msginfo(dest, num)) != NULL)) {
                                add_msginfo_to_cache(dest, newmsginfo, NULL);
-                               procmsg_msginfo_free(newmsginfo);
+                               procmsg_msginfo_free(&newmsginfo);
                        } else if ((newmsginfo = msgcache_get_msg(dest->cache, num)) != NULL) {
                                /* TODO: set default flags */
-                               procmsg_msginfo_free(newmsginfo);
+                               procmsg_msginfo_free(&newmsginfo);
                        }
                }
        }
@@ -3622,7 +3623,7 @@ static gint do_copy_msgs(FolderItem *dest, GSList *msglist, gboolean remove_sour
                                        hooks_invoke (MAIL_POSTFILTERING_HOOKLIST, newmsginfo);
                                }
                        }
-                       procmsg_msginfo_free(newmsginfo);
+                       procmsg_msginfo_free(&newmsginfo);
 
 
                        if (num > lastnum)
@@ -3731,7 +3732,7 @@ gint folder_item_remove_msg(FolderItem *item, gint num)
 
        msginfo = msgcache_get_msg(item->cache, num);
        if (msginfo && MSG_IS_LOCKED(msginfo->flags)) {
-               procmsg_msginfo_free(msginfo);
+               procmsg_msginfo_free(&msginfo);
                return -1;
        }
        ret = folder->klass->remove_msg(folder, item, num);
@@ -3740,7 +3741,7 @@ gint folder_item_remove_msg(FolderItem *item, gint num)
                if (msginfo != NULL) {
                        if (ret == 0)
                                remove_msginfo_from_cache(item, msginfo);
-                       procmsg_msginfo_free(msginfo);
+                       procmsg_msginfo_free(&msginfo);
                }
        }
 
@@ -4018,7 +4019,7 @@ static gchar *folder_item_get_tags_file(FolderItem *item)
 #endif
 
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
-                          "tagsdb", G_DIR_SEPARATOR_S,
+                          TAGS_DIR, G_DIR_SEPARATOR_S,
                           identifier, NULL);
        
        g_free(identifier);
@@ -4043,7 +4044,7 @@ static gpointer xml_to_folder_item(gpointer nodedata, gpointer data)
        cm_return_val_if_fail(folder != NULL, NULL);
 
        if (strcmp2(xmlnode->tag->tag, "folderitem") != 0) {
-               g_warning("tag name != \"folderitem\"\n");
+               g_warning("tag name != \"folderitem\"");
                return NULL;
        }
 
@@ -4090,7 +4091,7 @@ static Folder *folder_get_from_xml(GNode *node)
 
        xmlnode = node->data;
        if (strcmp2(xmlnode->tag->tag, "folder") != 0) {
-               g_warning("tag name != \"folder\"\n");
+               g_warning("tag name != \"folder\"");
                return NULL;
        }
        list = xmlnode->tag->attr;
@@ -4463,8 +4464,7 @@ void folder_item_apply_processing(FolderItem *item)
            || post_global_processing)
                filtering_move_and_copy_msgs(mlist);
        for (cur = mlist ; cur != NULL ; cur = cur->next) {
-               MsgInfo * msginfo = (MsgInfo *)cur->data;
-               procmsg_msginfo_free(msginfo);
+               procmsg_msginfo_free((MsgInfo **)&(cur->data));
        }
        g_slist_free(mlist);
        
@@ -4816,8 +4816,8 @@ gint folder_item_search_msgs_local        (Folder                 *folder,
 gboolean folder_local_name_ok(const gchar *name)
 {
 #ifdef G_OS_WIN32
-       if (name[0] == '.' || new_folder[strlen(name) - 1] == '.') {
-               alertpanel_error(_("A folder name cannot begin or end with a dot.");
+       if (name[0] == '.' || name[strlen(name) - 1] == '.') {
+               alertpanel_error(_("A folder name cannot begin or end with a dot."));
                return FALSE;
        }
 #endif