]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Don't delay setting mail event's log prefix
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 20 Jan 2022 10:42:57 +0000 (12:42 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 20 Jan 2022 11:05:22 +0000 (13:05 +0200)
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.

src/lib-storage/mail.c

index 20882ad62b8ded6e635a8ac96107721b0e2cd7c8..b3991d6f65c575ae4a60d78026a39c2be9c71585 100644 (file)
@@ -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)