dovecot-2.2: dsync: mailbox_metadata.cache_fields must be copied...

dovecot at dovecot.org dovecot at dovecot.org
Mon May 12 09:53:46 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/a21ac1261487
changeset: 17377:a21ac1261487
user:      Timo Sirainen <tss at iki.fi>
date:      Mon May 12 12:51:50 2014 +0300
description:
dsync: mailbox_metadata.cache_fields must be copied to permanent memory.
Any other call to mailbox_get_metadata() would have cleared the memory.

diffstat:

 src/doveadm/dsync/dsync-brain-mailbox.c |  34 ++++++++++++++++++++++++++++++++-
 src/doveadm/dsync/dsync-brain-private.h |   1 +
 src/doveadm/dsync/dsync-brain.c         |   3 ++
 3 files changed, 37 insertions(+), 1 deletions(-)

diffs (89 lines):

diff -r daa0b8e5cf2e -r a21ac1261487 src/doveadm/dsync/dsync-brain-mailbox.c
--- a/src/doveadm/dsync/dsync-brain-mailbox.c	Mon May 12 12:18:46 2014 +0300
+++ b/src/doveadm/dsync/dsync-brain-mailbox.c	Mon May 12 12:51:50 2014 +0300
@@ -60,6 +60,24 @@
 	return 0;
 }
 
+static void
+dsync_mailbox_cache_field_dup(ARRAY_TYPE(mailbox_cache_field) *dest,
+			      const ARRAY_TYPE(mailbox_cache_field) *src,
+			      pool_t pool)
+{
+	const struct mailbox_cache_field *src_field;
+	struct mailbox_cache_field *dest_field;
+
+	p_array_init(dest, pool, array_count(src));
+	array_foreach(src, src_field) {
+		dest_field = array_append_space(dest);
+		dest_field->name = p_strdup(pool, src_field->name);
+		dest_field->decision = src_field->decision;
+		dest_field->last_used = src_field->last_used;
+	}
+}
+
+
 static const struct dsync_mailbox_state *
 dsync_mailbox_state_find(struct dsync_brain *brain,
 			 const guid_128_t mailbox_guid)
@@ -122,6 +140,15 @@
 		dsync_brain_sync_init_box_states(brain);
 	}
 	brain->local_dsync_box = *local_dsync_box;
+	if (brain->dsync_box_pool != NULL)
+		p_clear(brain->dsync_box_pool);
+	else {
+		brain->dsync_box_pool =
+			pool_alloconly_create("dsync brain box pool", 1024);
+	}
+	dsync_mailbox_cache_field_dup(&brain->local_dsync_box.cache_fields,
+				      &local_dsync_box->cache_fields,
+				      brain->dsync_box_pool);
 	memset(&brain->remote_dsync_box, 0, sizeof(brain->remote_dsync_box));
 
 	state = dsync_mailbox_state_find(brain, local_dsync_box->mailbox_guid);
@@ -154,6 +181,9 @@
 			sizeof(remote_dsync_box->mailbox_guid)) == 0);
 
 	brain->remote_dsync_box = *remote_dsync_box;
+	dsync_mailbox_cache_field_dup(&brain->remote_dsync_box.cache_fields,
+				      &remote_dsync_box->cache_fields,
+				      brain->dsync_box_pool);
 
 	state = dsync_mailbox_state_find(brain, remote_dsync_box->mailbox_guid);
 	if (state != NULL) {
@@ -338,7 +368,9 @@
 	dsync_box_r->first_recent_uid = status.first_recent_uid;
 	dsync_box_r->highest_modseq = status.highest_modseq;
 	dsync_box_r->highest_pvt_modseq = status.highest_pvt_modseq;
-	dsync_box_r->cache_fields = *metadata.cache_fields;
+	dsync_mailbox_cache_field_dup(&dsync_box_r->cache_fields,
+				      metadata.cache_fields,
+				      pool_datastack_create());
 	dsync_box_r->have_guids = status.have_guids;
 	dsync_box_r->have_save_guids = status.have_save_guids;
 	dsync_box_r->have_only_guid128 = status.have_only_guid128;
diff -r daa0b8e5cf2e -r a21ac1261487 src/doveadm/dsync/dsync-brain-private.h
--- a/src/doveadm/dsync/dsync-brain-private.h	Mon May 12 12:18:46 2014 +0300
+++ b/src/doveadm/dsync/dsync-brain-private.h	Mon May 12 12:51:50 2014 +0300
@@ -77,6 +77,7 @@
 
 	struct mailbox *box;
 	struct dsync_mailbox local_dsync_box, remote_dsync_box;
+	pool_t dsync_box_pool;
 	/* list of mailbox states
 	   for master brain: given to brain at init and
 	   for slave brain: received from DSYNC_STATE_SLAVE_RECV_LAST_COMMON */
diff -r daa0b8e5cf2e -r a21ac1261487 src/doveadm/dsync/dsync-brain.c
--- a/src/doveadm/dsync/dsync-brain.c	Mon May 12 12:18:46 2014 +0300
+++ b/src/doveadm/dsync/dsync-brain.c	Mon May 12 12:51:50 2014 +0300
@@ -299,6 +299,9 @@
 		hash_table_iterate_deinit(&brain->mailbox_states_iter);
 	hash_table_destroy(&brain->mailbox_states);
 
+	if (brain->dsync_box_pool != NULL)
+		pool_unref(&brain->dsync_box_pool);
+
 	if (brain->lock_fd != -1) {
 		/* unlink the lock file before it gets unlocked */
 		if (unlink(brain->lock_path) < 0)


More information about the dovecot-cvs mailing list