[dovecot-cvs] dovecot/src/lib-index mail-cache-compress.c, 1.39, 1.40 mail-cache.c, 1.76, 1.77 mail-cache.h, 1.25, 1.26 mail-index-private.h, 1.62, 1.63 mail-index-sync-update.c, 1.90, 1.91 mail-index-sync.c, 1.66, 1.67 mail-index-transaction-private.h, 1.27, 1.28 mail-index-transaction-view.c, 1.15, 1.16 mail-index-transaction.c, 1.71, 1.72 mail-index-view-sync.c, 1.48, 1.49 mail-index-view.c, 1.41, 1.42 mail-index.c, 1.218, 1.219 mail-index.h, 1.156, 1.157 mail-transaction-log-view.c, 1.44, 1.45 mail-transaction-log.c, 1.105, 1.106 mail-transaction-log.h, 1.30, 1.31

cras at dovecot.org cras at dovecot.org
Sat Jan 14 20:47:41 EET 2006


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv16037/lib-index

Modified Files:
	mail-cache-compress.c mail-cache.c mail-cache.h 
	mail-index-private.h mail-index-sync-update.c 
	mail-index-sync.c mail-index-transaction-private.h 
	mail-index-transaction-view.c mail-index-transaction.c 
	mail-index-view-sync.c mail-index-view.c mail-index.c 
	mail-index.h mail-transaction-log-view.c 
	mail-transaction-log.c mail-transaction-log.h 
Log Message:
deinit, unref, destroy, close, free, etc. functions now take a pointer to
their data pointer, and set it to NULL. This makes double-frees less likely
to cause security holes.



Index: mail-cache-compress.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache-compress.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- mail-cache-compress.c	13 Jan 2006 20:26:13 -0000	1.39
+++ mail-cache-compress.c	14 Jan 2006 18:47:34 -0000	1.40
@@ -215,8 +215,8 @@
 	if (o_stream_flush(output) < 0) {
 		errno = output->stream_errno;
 		mail_cache_set_syscall_error(cache, "o_stream_flush()");
-		(void)mail_index_transaction_rollback(t);
-		o_stream_unref(output);
+		(void)mail_index_transaction_rollback(&t);
+		o_stream_unref(&output);
 		return -1;
 	}
 
@@ -225,15 +225,15 @@
 		(void)file_set_size(fd, MAIL_CACHE_INITIAL_SIZE);
 	}
 
-	o_stream_unref(output);
+	o_stream_unref(&output);
 
 	if (fdatasync(fd) < 0) {
 		mail_cache_set_syscall_error(cache, "fdatasync()");
-		(void)mail_index_transaction_rollback(t);
+		(void)mail_index_transaction_rollback(&t);
 		return -1;
 	}
 
-	return mail_index_transaction_commit(t, &seq, &offset);
+	return mail_index_transaction_commit(&t, &seq, &offset);
 }
 
 static int mail_cache_compress_locked(struct mail_cache *cache,

Index: mail-cache.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache.c,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -d -r1.76 -r1.77
--- mail-cache.c	13 Jan 2006 20:26:13 -0000	1.76
+++ mail-cache.c	14 Jan 2006 18:47:34 -0000	1.77
@@ -104,11 +104,11 @@
 		   happen often so we'll just mark cache to be compressed
 		   later which fixes this. */
 		cache->need_compress = TRUE;
-		mail_index_view_close(view);
+		mail_index_view_close(&view);
 		return 0;
 	}
 
-	mail_index_view_close(view);
+	mail_index_view_close(&view);
 	return 1;
 }
 
@@ -326,14 +326,16 @@
 	return cache;
 }
 
-void mail_cache_free(struct mail_cache *cache)
+void mail_cache_free(struct mail_cache **_cache)
 {
+	struct mail_cache *cache = *_cache;
+
+	*_cache = NULL;
 	if (cache->file_cache != NULL) {
 		mail_index_unregister_sync_lost_handler(cache->index,
 			mail_cache_sync_lost_handler);
 
-		file_cache_free(cache->file_cache);
-		cache->file_cache = NULL;
+		file_cache_free(&cache->file_cache);
 	}
 
 	mail_index_unregister_expunge_handler(cache->index, cache->ext_id);
@@ -381,14 +383,14 @@
 	ext = mail_index_view_get_ext(view, cache->ext_id);
 	if (ext == NULL) {
 		/* cache not used */
-		mail_index_view_close(view);
+		mail_index_view_close(&view);
 		return 0;
 	}
 
 	if (cache->hdr->file_seq != ext->reset_id) {
 		/* we want the latest cache file */
 		if ((ret = mail_cache_reopen(cache)) <= 0) {
-			mail_index_view_close(view);
+			mail_index_view_close(&view);
 			return ret;
 		}
 	}
@@ -425,7 +427,7 @@
 		}
 	}
 
-	mail_index_view_close(view);
+	mail_index_view_close(&view);
 	i_assert((ret <= 0 && !cache->locked) || (ret > 0 && cache->locked));
 	return ret;
 }
@@ -525,7 +527,7 @@
                 (void)mail_cache_header_fields_update(view->cache);
 
 	if (view->trans_view != NULL)
-		mail_index_view_close(view->trans_view);
+		mail_index_view_close(&view->trans_view);
 
 	array_free(&view->tmp_offsets);
 	buffer_free(view->cached_exists_buf);

Index: mail-cache.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-cache.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- mail-cache.h	13 Jan 2006 20:26:13 -0000	1.25
+++ mail-cache.h	14 Jan 2006 18:47:34 -0000	1.26
@@ -40,7 +40,7 @@
 
 struct mail_cache *mail_cache_open_or_create(struct mail_index *index);
 struct mail_cache *mail_cache_create(struct mail_index *index);
-void mail_cache_free(struct mail_cache *cache);
+void mail_cache_free(struct mail_cache **cache);
 
 /* Register fields. fields[].idx is updated to contain field index. */
 void mail_cache_register_fields(struct mail_cache *cache,

Index: mail-index-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-private.h,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- mail-index-private.h	13 Jan 2006 20:26:13 -0000	1.62
+++ mail-index-private.h	14 Jan 2006 18:47:34 -0000	1.63
@@ -229,7 +229,7 @@
 int mail_index_get_latest_header(struct mail_index *index,
 				 struct mail_index_header *hdr_r);
 /* Unreference given mapping and unmap it if it's dropped to zero. */
-void mail_index_unmap(struct mail_index *index, struct mail_index_map *map);
+void mail_index_unmap(struct mail_index *index, struct mail_index_map **map);
 struct mail_index_map *
 mail_index_map_clone(struct mail_index_map *map, uint32_t new_record_size);
 

Index: mail-index-sync-update.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-sync-update.c,v
retrieving revision 1.90
retrieving revision 1.91
diff -u -d -r1.90 -r1.91
--- mail-index-sync-update.c	13 Jan 2006 20:26:13 -0000	1.90
+++ mail-index-sync-update.c	14 Jan 2006 18:47:34 -0000	1.91
@@ -20,10 +20,10 @@
 	/* if map still exists after this, it's only in views. */
 	view->map->write_to_disk = FALSE;
 
-	mail_index_unmap(view->index, view->map);
+	mail_index_unmap(view->index, &view->map);
 	view->map = map;
 	view->map->refcount++;
-	mail_index_unmap(view->index, view->index->map);
+	mail_index_unmap(view->index, &view->index->map);
 	view->index->map = map;
 	view->index->hdr = &map->hdr;
 
@@ -625,7 +625,7 @@
 	}
 	i_assert(map->hdr.base_header_size >= sizeof(map->hdr));
 
-	mail_index_unmap(index, view->map);
+	mail_index_unmap(index, &view->map);
 	view->map = map;
 	view->map->refcount++;
 
@@ -681,7 +681,7 @@
 			}
 			if (map != index->map) {
 				map = index->map;
-				mail_index_unmap(view->index, view->map);
+				mail_index_unmap(view->index, &view->map);
 				view->map = map;
 				view->map->refcount++;
 			}

Index: mail-index-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-sync.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- mail-index-sync.c	13 Jan 2006 20:26:13 -0000	1.66
+++ mail-index-sync.c	14 Jan 2006 18:47:34 -0000	1.67
@@ -77,7 +77,7 @@
 		}
 	}
 
-	mail_index_keywords_free(keywords);
+	mail_index_keywords_free(&keywords);
 	t_pop();
 }
 
@@ -95,7 +95,7 @@
 						   MODIFY_REPLACE, keywords);
 		}
 	}
-	mail_index_keywords_free(keywords);
+	mail_index_keywords_free(&keywords);
 }
 
 static void mail_index_sync_add_append(struct mail_index_sync_ctx *ctx)
@@ -410,12 +410,12 @@
 
 	dummy_view = mail_index_dummy_view_open(index);
 	ctx->trans = mail_index_transaction_begin(dummy_view, FALSE, TRUE);
-	mail_index_view_close(dummy_view);
+	mail_index_view_close(&dummy_view);
 
 	if (mail_index_sync_set_log_view(ctx->view,
 					 index->hdr->log_file_seq,
 					 index->hdr->log_file_int_offset) < 0) {
-                mail_index_sync_rollback(ctx);
+                mail_index_sync_rollback(&ctx);
 		return -1;
 	}
 
@@ -433,11 +433,11 @@
 	if (seq != index->hdr->log_file_seq ||
 	    offset != index->hdr->log_file_ext_offset) {
 		if (mail_index_sync_commit_external(ctx) < 0) {
-			mail_index_sync_rollback(ctx);
+			mail_index_sync_rollback(&ctx);
 			return -1;
 		}
 
-		mail_index_view_close(ctx->view);
+		mail_index_view_close(&ctx->view);
 		ctx->view = mail_index_view_open(index);
 
 		if (mail_index_sync_set_log_view(ctx->view,
@@ -449,7 +449,7 @@
 	/* we need to have all the transactions sorted to optimize
 	   caller's mailbox access patterns */
 	if (mail_index_sync_read_and_sort(ctx, &seen_external) < 0) {
-                mail_index_sync_rollback(ctx);
+                mail_index_sync_rollback(&ctx);
 		return -1;
 	}
 
@@ -618,20 +618,24 @@
 		sync_list[i].idx = 0;
 }
 
-static void mail_index_sync_end(struct mail_index_sync_ctx *ctx)
+static void mail_index_sync_end(struct mail_index_sync_ctx **_ctx)
 {
+        struct mail_index_sync_ctx *ctx = *_ctx;
+
+	*_ctx = NULL;
 	mail_index_unlock(ctx->index, ctx->lock_id);
 
 	i_assert(!ctx->index->map->write_to_disk);
 	mail_transaction_log_sync_unlock(ctx->index->log);
 
-	mail_index_view_close(ctx->view);
-	mail_index_transaction_rollback(ctx->trans);
+	mail_index_view_close(&ctx->view);
+	mail_index_transaction_rollback(&ctx->trans);
 	i_free(ctx);
 }
 
-int mail_index_sync_commit(struct mail_index_sync_ctx *ctx)
+int mail_index_sync_commit(struct mail_index_sync_ctx **_ctx)
 {
+        struct mail_index_sync_ctx *ctx = *_ctx;
 	struct mail_index *index = ctx->index;
 	const struct mail_index_header *hdr;
 	uint32_t seq;
@@ -675,11 +679,11 @@
 	index->sync_log_file_seq = index->map->hdr.log_file_seq;
 	index->sync_log_file_offset = index->map->hdr.log_file_int_offset;
 
-	mail_index_sync_end(ctx);
+	mail_index_sync_end(_ctx);
 	return ret;
 }
 
-void mail_index_sync_rollback(struct mail_index_sync_ctx *ctx)
+void mail_index_sync_rollback(struct mail_index_sync_ctx **ctx)
 {
 	mail_index_sync_end(ctx);
 }

Index: mail-index-transaction-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-transaction-private.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- mail-index-transaction-private.h	13 Jan 2006 20:26:13 -0000	1.27
+++ mail-index-transaction-private.h	14 Jan 2006 18:47:34 -0000	1.28
@@ -47,7 +47,7 @@
 mail_index_transaction_lookup(struct mail_index_transaction *t, uint32_t seq);
 
 void mail_index_transaction_ref(struct mail_index_transaction *t);
-void mail_index_transaction_unref(struct mail_index_transaction *t);
+void mail_index_transaction_unref(struct mail_index_transaction **t);
 
 bool mail_index_seq_array_lookup(const array_t *buffer, uint32_t seq,
 				 unsigned int *idx_r);

Index: mail-index-transaction-view.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-transaction-view.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- mail-index-transaction-view.c	6 Jan 2006 12:48:55 -0000	1.15
+++ mail-index-transaction-view.c	14 Jan 2006 18:47:34 -0000	1.16
@@ -18,7 +18,7 @@
 	struct mail_index_view_transaction *tview =
 		(struct mail_index_view_transaction *)view;
 
-	mail_index_transaction_unref(tview->t);
+	mail_index_transaction_unref(&tview->t);
 	tview->parent->close(view);
 }
 

Index: mail-index-transaction.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-transaction.c,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -d -r1.71 -r1.72
--- mail-index-transaction.c	13 Jan 2006 20:26:13 -0000	1.71
+++ mail-index-transaction.c	14 Jan 2006 18:47:34 -0000	1.72
@@ -84,7 +84,7 @@
 		array_free(&t->ext_resets);
 
 	mail_index_view_transaction_unref(t->view);
-	mail_index_view_close(t->view);
+	mail_index_view_close(&t->view);
 	i_free(t);
 }
 
@@ -93,8 +93,11 @@
 	t->refcount++;
 }
 
-void mail_index_transaction_unref(struct mail_index_transaction *t)
+void mail_index_transaction_unref(struct mail_index_transaction **_t)
 {
+	struct mail_index_transaction *t = *_t;
+
+	*_t = NULL;
 	if (--t->refcount == 0)
 		mail_index_transaction_free(t);
 }
@@ -194,14 +197,15 @@
 		rec1->uid > rec2->uid ? 1 : 0;
 }
 
-int mail_index_transaction_commit(struct mail_index_transaction *t,
+int mail_index_transaction_commit(struct mail_index_transaction **_t,
 				  uint32_t *log_file_seq_r,
 				  uoff_t *log_file_offset_r)
 {
+	struct mail_index_transaction *t = *_t;
 	int ret;
 
 	if (mail_index_view_is_inconsistent(t->view)) {
-		mail_index_transaction_rollback(t);
+		mail_index_transaction_rollback(_t);
 		return -1;
 	}
 
@@ -225,17 +229,19 @@
 						  log_file_offset_r);
 	}
 
-	mail_index_transaction_unref(t);
+	mail_index_transaction_unref(_t);
 	return ret;
 }
 
-void mail_index_transaction_rollback(struct mail_index_transaction *t)
+void mail_index_transaction_rollback(struct mail_index_transaction **_t)
 {
+	struct mail_index_transaction *t = *_t;
+
 	if (t->cache_trans_ctx != NULL) {
 		mail_cache_transaction_rollback(t->cache_trans_ctx);
                 t->cache_trans_ctx = NULL;
 	}
-        mail_index_transaction_unref(t);
+        mail_index_transaction_unref(_t);
 }
 
 struct mail_index_record *
@@ -800,9 +806,10 @@
 	return k;
 }
 
-void mail_index_keywords_free(struct mail_keywords *keywords)
+void mail_index_keywords_free(struct mail_keywords **keywords)
 {
-	i_free(keywords);
+	i_free(*keywords);
+	*keywords = NULL;
 }
 
 void mail_index_update_keywords(struct mail_index_transaction *t, uint32_t seq,

Index: mail-index-view-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-view-sync.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- mail-index-view-sync.c	13 Jan 2006 20:26:13 -0000	1.48
+++ mail-index-view-sync.c	14 Jan 2006 18:47:34 -0000	1.49
@@ -259,7 +259,7 @@
 		map = mail_index_map_clone(view->map,
 					   view->map->hdr.record_size);
 		view->map->records_count = old_records_count;
-		mail_index_unmap(view->index, view->map);
+		mail_index_unmap(view->index, &view->map);
 		view->map = map;
 
 		if (ctx->sync_map_update) {
@@ -522,12 +522,14 @@
 		array_delete(&view->log_syncs, 0, i);
 }
 
-void mail_index_view_sync_end(struct mail_index_view_sync_ctx *ctx)
+void mail_index_view_sync_end(struct mail_index_view_sync_ctx **_ctx)
 {
+        struct mail_index_view_sync_ctx *ctx = *_ctx;
         struct mail_index_view *view = ctx->view;
 
 	i_assert(view->syncing);
 
+	*_ctx = NULL;
 	if (ctx->sync_map_update)
 		mail_index_sync_map_deinit(&ctx->sync_map_ctx);
 	mail_index_view_sync_clean_log_syncs(ctx);
@@ -539,7 +541,7 @@
 	}
 
 	if (view->sync_new_map != NULL) {
-		mail_index_unmap(view->index, view->map);
+		mail_index_unmap(view->index, &view->map);
 		view->map = view->sync_new_map;
 		view->sync_new_map = NULL;
 	}

Index: mail-index-view.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-view.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- mail-index-view.c	13 Jan 2006 20:26:13 -0000	1.41
+++ mail-index-view.c	14 Jan 2006 18:47:34 -0000	1.42
@@ -34,11 +34,11 @@
 	i_assert(view->refcount == 0);
 
 	mail_index_view_unlock(view);
-	mail_transaction_log_view_close(view->log_view);
+	mail_transaction_log_view_close(&view->log_view);
 
 	if (array_is_created(&view->log_syncs))
 		array_free(&view->log_syncs);
-	mail_index_unmap(view->index, view->map);
+	mail_index_unmap(view->index, &view->map);
 	if (array_is_created(&view->map_refs)) {
 		mail_index_view_unref_maps(view);
 		array_free(&view->map_refs);
@@ -153,15 +153,15 @@
 
 void mail_index_view_unref_maps(struct mail_index_view *view)
 {
-	struct mail_index_map *const *maps;
+	struct mail_index_map **maps;
 	unsigned int i, count;
 
 	if (!array_is_created(&view->map_refs))
 		return;
 
-	maps = array_get(&view->map_refs, &count);
+	maps = array_get_modifyable(&view->map_refs, &count);
 	for (i = 0; i < count; i++)
-		mail_index_unmap(view->index, maps[i]);
+		mail_index_unmap(view->index, &maps[i]);
 
 	array_clear(&view->map_refs);
 }
@@ -439,8 +439,11 @@
 	return 0;
 }
 
-void mail_index_view_close(struct mail_index_view *view)
+void mail_index_view_close(struct mail_index_view **_view)
 {
+	struct mail_index_view *view = *_view;
+
+	*_view = NULL;
 	if (--view->refcount > 0)
 		return;
 

Index: mail-index.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.218
retrieving revision 1.219
diff -u -d -r1.218 -r1.219
--- mail-index.c	13 Jan 2006 20:26:13 -0000	1.218
+++ mail-index.c	14 Jan 2006 18:47:34 -0000	1.219
@@ -50,8 +50,11 @@
 	return index;
 }
 
-void mail_index_free(struct mail_index *index)
+void mail_index_free(struct mail_index **_index)
 {
+	struct mail_index *index = *_index;
+
+	*_index = NULL;
 	mail_index_close(index);
 
 	hash_destroy(index->keywords_hash);
@@ -569,8 +572,11 @@
 	}
 }
 
-void mail_index_unmap(struct mail_index *index, struct mail_index_map *map)
+void mail_index_unmap(struct mail_index *index, struct mail_index_map **_map)
 {
+	struct mail_index_map *map = *_map;
+
+	*_map = NULL;
 	if (--map->refcount > 0)
 		return;
 
@@ -819,7 +825,7 @@
 					  max_seq, max_offset,
 					  MAIL_TRANSACTION_TYPE_MASK) <= 0) {
 		/* can't use it. sync by re-reading index. */
-		mail_transaction_log_view_close(log_view);
+		mail_transaction_log_view_close(&log_view);
 		return 0;
 	}
 
@@ -847,8 +853,8 @@
 		index->map->hdr.log_file_ext_offset = prev_offset;
 
 	mail_index_sync_map_deinit(&sync_map_ctx);
-	mail_index_view_close(view);
-	mail_transaction_log_view_close(log_view);
+	mail_index_view_close(&view);
+	mail_transaction_log_view_close(&log_view);
 
 	*map = index->map;
 	index->map = NULL;
@@ -1031,7 +1037,7 @@
 
 	if (ret <= 0) {
 		mail_index_map_clear(index, map);
-		mail_index_unmap(index, map);
+		mail_index_unmap(index, &map);
 		index->mapping = FALSE;
 		return ret;
 	}
@@ -1508,20 +1514,12 @@
 
 void mail_index_close(struct mail_index *index)
 {
-	if (index->log != NULL) {
-		mail_transaction_log_close(index->log);
-		index->log = NULL;
-	}
-
-	if (index->map != NULL) {
-		mail_index_unmap(index, index->map);
-		index->map = NULL;
-	}
-
-	if (index->cache != NULL) {
-		mail_cache_free(index->cache);
-		index->cache = NULL;
-	}
+	if (index->log != NULL)
+		mail_transaction_log_close(&index->log);
+	if (index->map != NULL)
+		mail_index_unmap(index, &index->map);
+	if (index->cache != NULL)
+		mail_cache_free(&index->cache);
 
 	if (index->fd != -1) {
 		if (close(index->fd) < 0)
@@ -1529,10 +1527,8 @@
 		index->fd = -1;
 	}
 
-	i_free(index->copy_lock_path);
-	index->copy_lock_path = NULL;
-	i_free(index->filepath);
-	index->filepath = NULL;
+	i_free_and_null(index->copy_lock_path);
+	i_free_and_null(index->filepath);
 
 	index->indexid = 0;
 	index->opened = FALSE;
@@ -1587,12 +1583,12 @@
 		mail_index_unlock(index, lock_id);
 
 	if (ret == 0) {
-		mail_index_unmap(index, old_map);
+		mail_index_unmap(index, &old_map);
 		if (close(old_fd) < 0)
 			mail_index_set_syscall_error(index, "close()");
 	} else {
 		if (index->map != NULL)
-			mail_index_unmap(index, index->map);
+			mail_index_unmap(index, &index->map);
 		if (index->fd != -1) {
 			if (close(index->fd) < 0)
 				mail_index_set_syscall_error(index, "close()");

Index: mail-index.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index.h,v
retrieving revision 1.156
retrieving revision 1.157
diff -u -d -r1.156 -r1.157
--- mail-index.h	13 Jan 2006 20:26:13 -0000	1.156
+++ mail-index.h	14 Jan 2006 18:47:35 -0000	1.157
@@ -150,7 +150,7 @@
 struct mail_index_view_sync_ctx;
 
 struct mail_index *mail_index_alloc(const char *dir, const char *prefix);
-void mail_index_free(struct mail_index *index);
+void mail_index_free(struct mail_index **index);
 
 void mail_index_set_permissions(struct mail_index *index,
 				mode_t mode, gid_t gid);
@@ -170,7 +170,7 @@
    only when you synchronize it. The view acquires required locks
    automatically, but you'll have to drop them manually. */
 struct mail_index_view *mail_index_view_open(struct mail_index *index);
-void mail_index_view_close(struct mail_index_view *view);
+void mail_index_view_close(struct mail_index_view **view);
 
 /* Returns the index for given view. */
 struct mail_index *mail_index_view_get_index(struct mail_index_view *view);
@@ -193,10 +193,10 @@
 struct mail_index_transaction *
 mail_index_transaction_begin(struct mail_index_view *view,
 			     bool hide, bool external);
-int mail_index_transaction_commit(struct mail_index_transaction *t,
+int mail_index_transaction_commit(struct mail_index_transaction **t,
 				  uint32_t *log_file_seq_r,
 				  uoff_t *log_file_offset_r);
-void mail_index_transaction_rollback(struct mail_index_transaction *t);
+void mail_index_transaction_rollback(struct mail_index_transaction **t);
 
 /* Returns a view to transaction. Currently this differs from normal view only
    in that it contains newly appended messages in transaction. The view can
@@ -241,10 +241,10 @@
    go through all the sync records again with mail_index_sync_next(). */
 void mail_index_sync_reset(struct mail_index_sync_ctx *ctx);
 /* Commit synchronization by writing all changes to mail index file. */
-int mail_index_sync_commit(struct mail_index_sync_ctx *ctx);
+int mail_index_sync_commit(struct mail_index_sync_ctx **ctx);
 /* Rollback synchronization - none of the changes listed by sync_next() are
    actually written to index file. */
-void mail_index_sync_rollback(struct mail_index_sync_ctx *ctx);
+void mail_index_sync_rollback(struct mail_index_sync_ctx **ctx);
 
 /* Mark index file corrupted. Invalidates all views. */
 void mail_index_mark_corrupted(struct mail_index *index);
@@ -265,7 +265,7 @@
 const uint32_t *
 mail_index_view_sync_get_expunges(struct mail_index_view_sync_ctx *ctx,
 				 unsigned int *count_r);
-void mail_index_view_sync_end(struct mail_index_view_sync_ctx *ctx);
+void mail_index_view_sync_end(struct mail_index_view_sync_ctx **ctx);
 
 /* Returns the index header. */
 const struct mail_index_header *
@@ -333,7 +333,7 @@
 mail_index_keywords_create_from_indexes(struct mail_index_transaction *t,
 					const array_t *keyword_indexes);
 /* Free the keywords. */
-void mail_index_keywords_free(struct mail_keywords *keywords);
+void mail_index_keywords_free(struct mail_keywords **keywords);
 /* Update keywords for given message. */
 void mail_index_update_keywords(struct mail_index_transaction *t, uint32_t seq,
 				enum modify_type modify_type,

Index: mail-transaction-log-view.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log-view.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- mail-transaction-log-view.c	13 Jan 2006 20:26:13 -0000	1.44
+++ mail-transaction-log-view.c	14 Jan 2006 18:47:35 -0000	1.45
@@ -42,11 +42,14 @@
 	return view;
 }
 
-void mail_transaction_log_view_close(struct mail_transaction_log_view *view)
+void mail_transaction_log_view_close(struct mail_transaction_log_view **_view)
 {
+        struct mail_transaction_log_view *view = *_view;
 	struct mail_transaction_log_view **p;
 	struct mail_transaction_log_file *file;
 
+	*_view = NULL;
+
 	for (p = &view->log->views; *p != NULL; p = &(*p)->next) {
 		if (*p == view) {
 			*p = view->next;

Index: mail-transaction-log.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log.c,v
retrieving revision 1.105
retrieving revision 1.106
diff -u -d -r1.105 -r1.106
--- mail-transaction-log.c	13 Jan 2006 20:26:13 -0000	1.105
+++ mail-transaction-log.c	14 Jan 2006 18:47:35 -0000	1.106
@@ -242,7 +242,7 @@
 	if (log->head == NULL) {
 		/* fallback to in-memory indexes */
 		if (mail_index_move_to_memory(index) < 0) {
-			mail_transaction_log_close(log);
+			mail_transaction_log_close(&log);
 			return NULL;
 		}
 		log->head = mail_transaction_log_file_open_or_create(log, path);
@@ -255,15 +255,17 @@
 		   shouldn't happen except in race conditions.
 		   lock them and check again */
 		if (mail_transaction_log_check_file_seq(log) < 0) {
-			mail_transaction_log_close(log);
+			mail_transaction_log_close(&log);
 			return NULL;
 		}
 	}
 	return log;
 }
 
-void mail_transaction_log_close(struct mail_transaction_log *log)
+void mail_transaction_log_close(struct mail_transaction_log **_log)
 {
+	struct mail_transaction_log *log = *_log;
+
 	mail_transaction_log_views_close(log);
 
 	if (log->head != NULL) {
@@ -271,6 +273,7 @@
 		mail_transaction_logs_clean(log);
 	}
 
+	*_log = NULL;
 	log->index->log = NULL;
 	i_free(log);
 }

Index: mail-transaction-log.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- mail-transaction-log.h	13 Jan 2006 20:26:13 -0000	1.30
+++ mail-transaction-log.h	14 Jan 2006 18:47:35 -0000	1.31
@@ -107,13 +107,13 @@
 
 struct mail_transaction_log *
 mail_transaction_log_open_or_create(struct mail_index *index);
-void mail_transaction_log_close(struct mail_transaction_log *log);
+void mail_transaction_log_close(struct mail_transaction_log **log);
 
 int mail_transaction_log_move_to_memory(struct mail_transaction_log *log);
 
 struct mail_transaction_log_view *
 mail_transaction_log_view_open(struct mail_transaction_log *log);
-void mail_transaction_log_view_close(struct mail_transaction_log_view *view);
+void mail_transaction_log_view_close(struct mail_transaction_log_view **view);
 
 /* Set view boundaries. Returns -1 if error, 0 if files are lost, 1 if ok. */
 int



More information about the dovecot-cvs mailing list