2007-08-13 [wwp] 2.10.0cvs118
[claws.git] / src / msgcache.c
index 4323108dba7ca69f6ee0a6c574fef9b3ed642d73..84bdb67145090e7995b4780b58e7e0299f33ee1f 100644 (file)
@@ -4,7 +4,7 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -13,8 +13,8 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 
  */
 
 #ifdef HAVE_CONFIG_H
@@ -395,7 +395,7 @@ static FILE *msgcache_open_data_file(const gchar *file, guint version,
 
        if (mode == DATA_WRITE) {
                int w_err = 0, wrote = 0;
-               if ((fp = g_fopen(file, "w+")) == NULL) {
+               if ((fp = g_fopen(file, "wb")) == NULL) {
                        FILE_OP_ERROR(file, "fopen");
                        return NULL;
                }
@@ -596,8 +596,10 @@ MsgCache *msgcache_read_cache(FolderItem *item, const gchar *cache_file)
                tmp_flags |= MSG_DRAFT;
        }
 
-       if (msgcache_read_cache_data_str(fp, &srccharset, NULL) < 0)
+       if (msgcache_read_cache_data_str(fp, &srccharset, NULL) < 0) {
+               fclose(fp);
                return NULL;
+       }
        dstcharset = CS_UTF_8;
        if (srccharset == NULL || dstcharset == NULL) {
                conv = NULL;
@@ -638,6 +640,7 @@ MsgCache *msgcache_read_cache(FolderItem *item, const gchar *cache_file)
                        if (!hMapping)
                                goto w32_fail;
                        cache_data = (unsigned char *)MapViewOfFile(hMapping, FILE_MAP_COPY, 0, 0, 0);
+                       CloseHandle (hMapping);
                w32_fail:
                        ;
 #else
@@ -820,6 +823,7 @@ void msgcache_read_mark(MsgCache *cache, const gchar *mark_file)
                        if (!hMapping)
                                goto w32_fail2;
                        cache_data = (unsigned char *)MapViewOfFile(hMapping, FILE_MAP_COPY, 0, 0, 0);
+                       CloseHandle (hMapping);
                w32_fail2:
                        ;
 #else
@@ -903,6 +907,7 @@ void msgcache_read_tags(MsgCache *cache, const gchar *tags_file)
                        if (!hMapping)
                                goto w32_fail6;
                        cache_data = (unsigned char *)MapViewOfFile(hMapping, FILE_MAP_COPY, 0, 0, 0);
+                       CloseHandle (hMapping);
                w32_fail6:
                        ;
 #else
@@ -1175,6 +1180,7 @@ gint msgcache_write(const gchar *cache_file, const gchar *mark_file, const gchar
        if (write_fps.cache_fp == NULL) {
                g_free(new_cache);
                g_free(new_mark);
+               g_free(new_tags);
                return -1;
        }
 
@@ -1237,6 +1243,7 @@ gint msgcache_write(const gchar *cache_file, const gchar *mark_file, const gchar
                        if (!hMapping)
                                goto w32_fail3;
                        cache_data = (unsigned char *)MapViewOfFile(hMapping, FILE_MAP_COPY, 0, 0, 0);
+                       CloseHandle (hMapping);
                w32_fail3:
                        ;
 #else
@@ -1256,6 +1263,7 @@ gint msgcache_write(const gchar *cache_file, const gchar *mark_file, const gchar
                                if (!hMapping)
                                        goto w32_fail4;
                                mark_data = (unsigned char *)MapViewOfFile(hMapping, FILE_MAP_COPY, 0, 0, 0);
+                               CloseHandle (hMapping);
                        w32_fail4:
                                ;
 #else
@@ -1282,6 +1290,7 @@ gint msgcache_write(const gchar *cache_file, const gchar *mark_file, const gchar
                                                if (!hMapping)
                                                        goto w32_fail5;
                                                tags_data = (unsigned char *)MapViewOfFile(hMapping, FILE_MAP_COPY, 0, 0, 0);
+                                               CloseHandle (hMapping);
                                        w32_fail5:
                                                ;
 #else