]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: mail_cache_header_add_field_locked() - Move unlocking to caller
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 20 Mar 2020 14:42:45 +0000 (16:42 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Wed, 15 Apr 2020 08:57:20 +0000 (08:57 +0000)
src/lib-index/mail-cache-transaction.c

index 54980bc3e0eefc05406d4ecc2272c8e03efa58c0..9a83a8ac35d4803db2be2dfd5735f6fa57d1c2e0 100644 (file)
@@ -651,15 +651,11 @@ mail_cache_header_add_field_locked(struct mail_cache *cache,
        int ret;
 
        /* re-read header to make sure we don't lose any fields. */
-       if (mail_cache_header_fields_read(cache) < 0) {
-               (void)mail_cache_unlock(cache);
+       if (mail_cache_header_fields_read(cache) < 0)
                return -1;
-       }
 
        if (cache->field_file_map[field_idx] != (uint32_t)-1) {
                /* it was already added */
-               if (mail_cache_unlock(cache) < 0)
-                       return -1;
                return 0;
        }
 
@@ -682,9 +678,6 @@ mail_cache_header_add_field_locked(struct mail_cache *cache,
                                     "lost unexpectedly", cache->filepath);
                ret = -1;
        }
-
-       if (mail_cache_unlock(cache) < 0)
-               ret = -1;
        return ret;
 }
 
@@ -692,6 +685,7 @@ static int mail_cache_header_add_field(struct mail_cache_transaction_ctx *ctx,
                                       unsigned int field_idx)
 {
        struct mail_cache *cache = ctx->cache;
+       int ret;
 
        if (MAIL_INDEX_IS_IN_MEMORY(cache->index)) {
                if (cache->file_fields_count <= field_idx) {
@@ -721,7 +715,10 @@ static int mail_cache_header_add_field(struct mail_cache_transaction_ctx *ctx,
                if (mail_cache_transaction_lock(ctx) <= 0)
                        return -1;
        }
-       return mail_cache_header_add_field_locked(cache, field_idx);
+       ret = mail_cache_header_add_field_locked(cache, field_idx);
+       if (mail_cache_unlock(cache) < 0)
+               ret = -1;
+       return ret;
 }
 
 static int