]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Fix assert-crash with lock_method=dotlock
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 7 Feb 2018 14:17:13 +0000 (16:17 +0200)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Fri, 9 Feb 2018 14:32:29 +0000 (16:32 +0200)
The dotlock wasn't deleted in all code paths. Fix this by simplifying
the unlocking to be done the same way with and without dotlock.

Fixes:
Panic: file mail-cache.c: line 624 (mail_cache_lock_file): assertion failed: (cache->dotlock == NULL)

src/lib-index/mail-cache-private.h
src/lib-index/mail-cache.c

index 38be5559ab1ce2a7cf6be43f6eae0eae2a47e0fa..cb1c6efc304447d76fcd51fcddddd1a258e46ef6 100644 (file)
@@ -108,7 +108,6 @@ struct mail_cache {
        unsigned int remap_counter;
 
        struct dotlock_settings dotlock_settings;
-       struct dotlock *dotlock;
        struct file_lock *file_lock;
 
        /* mmap_disable=no: hdr points to data / NULL when cache is invalid.
index 7fba96aabee988199bf4b542d140c151da5fe87a..631d885521f9387af38bafc826297882bb866f66 100644 (file)
@@ -611,8 +611,8 @@ static int mail_cache_lock_file(struct mail_cache *cache, bool nonblock)
                nonblock = TRUE;
        }
 
+       i_assert(cache->file_lock == NULL);
        if (cache->index->lock_method != FILE_LOCK_METHOD_DOTLOCK) {
-               i_assert(cache->file_lock == NULL);
                timeout_secs = I_MIN(MAIL_CACHE_LOCK_TIMEOUT,
                                     cache->index->max_lock_timeout_secs);
 
@@ -621,14 +621,15 @@ static int mail_cache_lock_file(struct mail_cache *cache, bool nonblock)
                                         nonblock ? 0 : timeout_secs,
                                         &cache->file_lock);
        } else {
+               struct dotlock *dotlock;
                enum dotlock_create_flags flags =
                        nonblock ? DOTLOCK_CREATE_FLAG_NONBLOCK : 0;
 
-               i_assert(cache->dotlock == NULL);
                ret = file_dotlock_create(&cache->dotlock_settings,
-                                         cache->filepath, flags,
-                                         &cache->dotlock);
-               if (ret < 0) {
+                                         cache->filepath, flags, &dotlock);
+               if (ret > 0)
+                       cache->file_lock = file_lock_from_dotlock(&dotlock);
+               else if (ret < 0) {
                        mail_cache_set_syscall_error(cache,
                                                     "file_dotlock_create()");
                }
@@ -648,10 +649,7 @@ static int mail_cache_lock_file(struct mail_cache *cache, bool nonblock)
 
 static void mail_cache_unlock_file(struct mail_cache *cache)
 {
-       if (cache->index->lock_method != FILE_LOCK_METHOD_DOTLOCK)
-               file_unlock(&cache->file_lock);
-       else
-               file_dotlock_delete(&cache->dotlock);
+       file_unlock(&cache->file_lock);
 }
 
 static int