[dovecot-cvs] dovecot/src/lib-index mail-cache.c,1.44,1.45

cras at dovecot.org cras at dovecot.org
Wed Jul 28 19:31:56 EEST 2004


Update of /home/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv30506

Modified Files:
	mail-cache.c 
Log Message:
mail_cache_lock() crashed if index wasn't locked while it was called.



Index: mail-cache.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-cache.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- mail-cache.c	24 Jul 2004 21:19:20 -0000	1.44
+++ mail-cache.c	28 Jul 2004 16:31:54 -0000	1.45
@@ -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;
 }
 



More information about the dovecot-cvs mailing list