From: Timo Sirainen Date: Thu, 20 Jan 2022 10:42:57 +0000 (+0200) Subject: lib-storage: Don't delay setting mail event's log prefix X-Git-Tag: 2.3.19~137 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6f703021eb18380164ba1c3d306d13d8e32f2783;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Don't delay setting mail event's log prefix This caused crashes if the mail event was kept referenced and used for logging after struct mail was already freed. With the delayed mail event creation the log prefix shouldn't be much of a performance problem, so just set the prefix immediately. Partially reverts bc68e1c368db746557829f67556f3c72943b7956. --- diff --git a/src/lib-storage/mail.c b/src/lib-storage/mail.c index 20882ad62b..b3991d6f65 100644 --- a/src/lib-storage/mail.c +++ b/src/lib-storage/mail.c @@ -122,19 +122,6 @@ static bool index_mail_get_age_days(struct mail *mail, int *days_r) return TRUE; } -static const char *mail_event_log_callback(struct mail_private *p) -{ - char uid_buf[MAX_INT_STRLEN]; - - /* Replace the log prefix callback with an explicit prefix, so this - callback doesn't have to be called more than once. */ - const char *prefix = t_strconcat( - p->mail.saving ? "saving UID " : "UID ", - dec2str_buf(uid_buf, p->mail.uid), ": ", NULL); - event_set_append_log_prefix(p->_event, prefix); - return prefix; -} - void mail_event_create(struct mail *mail) { struct mail_private *p = (struct mail_private *)mail; @@ -150,11 +137,11 @@ void mail_event_create(struct mail *mail) if (index_mail_get_age_days(mail, &age_days)) event_add_int(p->_event, "mail_age_days", age_days); - /* The mail events may be created often, but most of the time the log - prefix isn't needed. We can save some CPU by delaying the prefix - generation until it's actually used. */ - event_set_log_prefix_callback(p->_event, FALSE, - mail_event_log_callback, p); + char uid_buf[MAX_INT_STRLEN]; + const char *prefix = t_strconcat( + p->mail.saving ? "saving UID " : "UID ", + dec2str_buf(uid_buf, p->mail.uid), ": ", NULL); + event_set_append_log_prefix(p->_event, prefix); } struct event *mail_event(struct mail *mail)