From: Timo Sirainen Date: Tue, 27 Dec 2022 12:03:04 +0000 (+0200) Subject: lib-index: mail_cache_purge_later() - Change reason string to format string X-Git-Tag: 2.4.0~3225 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c8eb66d8fc9324a46725ed65bc36519d682f66b9;p=thirdparty%2Fdovecot%2Fcore.git lib-index: mail_cache_purge_later() - Change reason string to format string 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(). --- diff --git a/src/lib-index/mail-cache-fields.c b/src/lib-index/mail-cache-fields.c index 4f977ad1e8..5080bdef9a 100644 --- a/src/lib-index/mail-cache-fields.c +++ b/src/lib-index/mail-cache-fields.c @@ -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; } diff --git a/src/lib-index/mail-cache-purge.c b/src/lib-index/mail-cache-purge.c index 789689f854..b93860627c 100644 --- a/src/lib-index/mail-cache-purge.c +++ b/src/lib-index/mail-cache-purge.c @@ -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) diff --git a/src/lib-index/mail-cache.c b/src/lib-index/mail-cache.c index bd3c9396b2..9016414e75 100644 --- a/src/lib-index/mail-cache.c +++ b/src/lib-index/mail-cache.c @@ -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); } } diff --git a/src/lib-index/mail-cache.h b/src/lib-index/mail-cache.h index 88ab2ad423..9adc9f5d56 100644 --- a/src/lib-index/mail-cache.h +++ b/src/lib-index/mail-cache.h @@ -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.