changeset 19530:7104de520141

lib-storage: mail_add_temp_wanted_fields() was reading already-freed memory. This mainly happened with mail_log plugin enabled.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 04 Jan 2016 12:02:12 -0500
parents 0c2e2cba8a5b
children 21e41add1925
files src/lib-storage/index/index-mail.c
diffstat 1 files changed, 5 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/index-mail.c	Mon Jan 04 11:47:24 2016 -0500
+++ b/src/lib-storage/index/index-mail.c	Mon Jan 04 12:02:12 2016 -0500
@@ -1816,6 +1816,7 @@
 {
 	struct index_mail *mail = (struct index_mail *)_mail;
 	struct index_mail_data *data = &mail->data;
+	struct mailbox_header_lookup_ctx *new_wanted_headers;
 	ARRAY_TYPE(const_string) names;
 	unsigned int i;
 
@@ -1833,11 +1834,12 @@
 		for (i = 0; i < headers->count; i++)
 			array_append(&names, &headers->name[i], 1);
 		array_append_zero(&names);
+		new_wanted_headers =
+			mailbox_header_lookup_init(_mail->box,
+						   array_idx(&names, 0));
 		if (data->wanted_headers != NULL)
 			mailbox_header_lookup_unref(&data->wanted_headers);
-		data->wanted_headers =
-			mailbox_header_lookup_init(_mail->box,
-						   array_idx(&names, 0));
+		data->wanted_headers = new_wanted_headers;
 	}
 	index_mail_update_access_parts_pre(_mail);
 	index_mail_update_access_parts_post(_mail);