changeset 1790:b101e678e7ac HEAD

Fixes memory/fd leaking with INDEX=MEMORY.
author Timo Sirainen <tss@iki.fi>
date Tue, 23 Sep 2003 22:34:34 +0300
parents e71256caeff9
children 924d5279293b
files src/lib-storage/index/index-storage.c src/lib-storage/index/index-storage.h src/lib-storage/index/maildir/maildir-storage.c src/lib-storage/index/mbox/mbox-storage.c
diffstat 4 files changed, 18 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/index-storage.c	Tue Sep 23 16:41:31 2003 +0300
+++ b/src/lib-storage/index/index-storage.c	Tue Sep 23 22:34:34 2003 +0300
@@ -57,27 +57,31 @@
 	indexes = list;
 }
 
-struct mail_index *index_storage_lookup_ref(const char *path)
+struct mail_index *
+index_storage_lookup_ref(const char *index_dir, const char *path)
 {
 	struct index_list **list, *rec;
 	struct mail_index *match;
 	struct stat st1, st2;
 	int destroy_count;
 
-	if (stat(path, &st1) < 0)
-		return NULL;
+	if (index_dir != NULL) {
+		if (stat(index_dir, &st1) < 0)
+			return NULL;
+	}
 
-	/* compare inodes so we don't break even with symlinks */
+	/* compare index_dir inodes so we don't break even with symlinks.
+	   for in-memory indexes compare just mailbox paths */
 	destroy_count = 0; match = NULL;
 	for (list = &indexes; *list != NULL;) {
 		rec = *list;
 
-		if (stat(rec->index->dir, &st2) == 0) {
-			if (st1.st_ino == st2.st_ino &&
-			    st1.st_dev == st2.st_dev) {
-				rec->refcount++;
-				match = rec->index;
-			}
+		if ((index_dir != NULL && stat(rec->index->dir, &st2) == 0 &&
+		     st1.st_ino == st2.st_ino && st1.st_dev == st2.st_dev) ||
+		    (index_dir == NULL &&
+		     strcmp(path, rec->index->mailbox_path) == 0)) {
+			rec->refcount++;
+			match = rec->index;
 		}
 
 		if (rec->refcount == 0) {
--- a/src/lib-storage/index/index-storage.h	Tue Sep 23 16:41:31 2003 +0300
+++ b/src/lib-storage/index/index-storage.h	Tue Sep 23 22:34:34 2003 +0300
@@ -55,7 +55,8 @@
 		       enum mail_lock_type lock_type);
 
 void index_storage_add(struct mail_index *index);
-struct mail_index *index_storage_lookup_ref(const char *path);
+struct mail_index *
+index_storage_lookup_ref(const char *index_dir, const char *path);
 void index_storage_unref(struct mail_index *index);
 void index_storage_destroy_unrefed(void);
 
--- a/src/lib-storage/index/maildir/maildir-storage.c	Tue Sep 23 16:41:31 2003 +0300
+++ b/src/lib-storage/index/maildir/maildir-storage.c	Tue Sep 23 22:34:34 2003 +0300
@@ -397,7 +397,7 @@
 	index_dir = maildir_get_index_path(storage, name);
 	control_dir = maildir_get_control_path(storage, name);
 
-	index = index_storage_lookup_ref(index_dir);
+	index = index_storage_lookup_ref(index_dir, path);
 	if (index == NULL) {
 		index = maildir_index_alloc(path, index_dir, control_dir);
 		index_storage_add(index);
--- a/src/lib-storage/index/mbox/mbox-storage.c	Tue Sep 23 16:41:31 2003 +0300
+++ b/src/lib-storage/index/mbox/mbox-storage.c	Tue Sep 23 22:34:34 2003 +0300
@@ -393,7 +393,7 @@
 		index_dir = mbox_get_index_dir(storage, name);
 	}
 
-	index = index_storage_lookup_ref(index_dir);
+	index = index_storage_lookup_ref(index_dir, path);
 	if (index == NULL) {
 		index = mbox_index_alloc(path, index_dir, index_dir);
 		index_storage_add(index);