changeset 2378:00a4d69a1d1c HEAD

mail_cache_lock() crashed if index wasn't locked while it was called.
author Timo Sirainen <tss@iki.fi>
date Wed, 28 Jul 2004 19:31:54 +0300
parents 8f5be0be3199
children 9a6d22b5bb7a
files src/lib-index/mail-cache.c
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-cache.c	Wed Jul 28 18:39:29 2004 +0300
+++ b/src/lib-index/mail-cache.c	Wed Jul 28 19:31:54 2004 +0300
@@ -265,6 +265,7 @@
 
 int mail_cache_lock(struct mail_cache *cache)
 {
+	unsigned int lock_id;
 	int i, ret;
 
 	i_assert(!cache->locked);
@@ -272,10 +273,15 @@
 	if (MAIL_CACHE_IS_UNUSABLE(cache))
 		return 0;
 
+	if (mail_index_lock_shared(cache->index, TRUE, &lock_id) < 0)
+		return -1;
+
 	if (cache->hdr->file_seq != cache->index->hdr->cache_file_seq) {
 		/* we want the latest cache file */
-		if ((ret = mail_cache_reopen(cache)) <= 0)
+		if ((ret = mail_cache_reopen(cache)) <= 0) {
+			mail_index_unlock(cache->index, lock_id);
 			return ret;
+		}
 	}
 
 	for (i = 0; i < 3; i++) {
@@ -293,13 +299,14 @@
 		/* okay, so it was just compressed. try again. */
 		mail_cache_unlock(cache);
 		if ((ret = mail_cache_reopen(cache)) <= 0)
-			return ret;
+			break;
 		ret = 0;
 	}
 
 	if (ret > 0)
 		cache->hdr_copy = *cache->hdr;
 
+	mail_index_unlock(cache->index, lock_id);
 	return ret;
 }