]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: mail_cache_purge_later() - Change reason string to format string
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 27 Dec 2022 12:03:04 +0000 (14:03 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 11 Jan 2023 21:50:37 +0000 (23:50 +0200)
This way callers don't have to allocate the string from data stack, which
also simplifies reducing data stack usage in
mail_cache_header_fields_read().

src/lib-index/mail-cache-fields.c
src/lib-index/mail-cache-purge.c
src/lib-index/mail-cache.c
src/lib-index/mail-cache.h

index 4f977ad1e8360fad2040eab378f2a0dbe6344d5c..5080bdef9a5576d954ab9e6224fc9c975eee2441 100644 (file)
@@ -325,8 +325,8 @@ mail_cache_header_fields_get_offset(struct mail_cache *cache,
        cache->last_field_header_offset = offset;
 
        if (next_count > cache->index->optimization_set.cache.purge_header_continue_count) {
-               mail_cache_purge_later(cache, t_strdup_printf(
-                       "Too many continued headers (%u)", next_count));
+               mail_cache_purge_later(cache,
+                       "Too many continued headers (%u)", next_count);
        }
 
        if (field_hdr_r != NULL) {
@@ -494,19 +494,19 @@ int mail_cache_header_fields_read(struct mail_cache *cache)
                case MAIL_CACHE_PURGE_DROP_DECISION_NONE:
                        break;
                case MAIL_CACHE_PURGE_DROP_DECISION_DROP:
-                       mail_cache_purge_later(cache, t_strdup_printf(
+                       mail_cache_purge_later(cache,
                                "Drop old field %s (last_used=%"PRIdTIME_T")",
                                cache->fields[fidx].field.name,
-                               cache->fields[fidx].field.last_used));
+                               cache->fields[fidx].field.last_used);
                        break;
                case MAIL_CACHE_PURGE_DROP_DECISION_TO_TEMP:
                        /* This cache decision change can cause the field to be
                           dropped for old mails, so do it via purging. */
-                       mail_cache_purge_later(cache, t_strdup_printf(
+                       mail_cache_purge_later(cache,
                                "Change cache decision to temp for old field %s "
                                "(last_used=%"PRIdTIME_T")",
                                cache->fields[fidx].field.name,
-                               cache->fields[fidx].field.last_used));
+                               cache->fields[fidx].field.last_used);
                        break;
                }
 
index 789689f85478ed7c1cb38482c8270cf4f35eb503..b93860627c43b8cbc53dbaeac478570258ea9601 100644 (file)
@@ -651,13 +651,19 @@ bool mail_cache_need_purge(struct mail_cache *cache, const char **reason_r)
        return TRUE;
 }
 
-void mail_cache_purge_later(struct mail_cache *cache, const char *reason)
+void mail_cache_purge_later(struct mail_cache *cache,
+                           const char *reason_format, ...)
 {
+       va_list args;
+
        i_assert(cache->hdr != NULL);
 
+       va_start(args, reason_format);
        cache->need_purge_file_seq = cache->hdr->file_seq;
        i_free(cache->need_purge_reason);
-       cache->need_purge_reason = i_strdup(reason);
+       cache->need_purge_reason = i_strdup_vprintf(reason_format, args);
+
+       va_end(args);
 }
 
 void mail_cache_purge_later_reset(struct mail_cache *cache)
index bd3c9396b2510cd0148d5275354c4fe0a92bd176..9016414e75ca6247aad61599971ee2c1ed4c1ba8 100644 (file)
@@ -269,7 +269,7 @@ static void mail_cache_update_need_purge(struct mail_cache *cache)
                        return;
                }
                if ((uoff_t)st.st_size >= set->purge_min_size)
-                       mail_cache_purge_later(cache, want_purge_reason);
+                       mail_cache_purge_later(cache, "%s", want_purge_reason);
        }
 
 }
index 88ab2ad423a5e18e289a5d97e816fc6edb58b8ad..9adc9f5d56afe87b64eacd2845ffd0492819c7ae 100644 (file)
@@ -94,7 +94,8 @@ mail_cache_register_get_list(struct mail_cache *cache, pool_t pool,
 /* Returns TRUE if cache should be purged. */
 bool mail_cache_need_purge(struct mail_cache *cache, const char **reason_r);
 /* Set cache file to be purged later. */
-void mail_cache_purge_later(struct mail_cache *cache, const char *reason);
+void mail_cache_purge_later(struct mail_cache *cache,
+                           const char *reason_format, ...) ATTR_FORMAT(2, 3);
 /* Don't try to purge the cache file later after all. */
 void mail_cache_purge_later_reset(struct mail_cache *cache);
 /* Purge cache file. Offsets are updated to given transaction.