# HG changeset patch # User Timo Sirainen # Date 1064345674 -10800 # Node ID b101e678e7ac624bb74a9741059f005cd177721b # Parent e71256caeff95e409d9053fd0bdd4827849e2775 Fixes memory/fd leaking with INDEX=MEMORY. diff -r e71256caeff9 -r b101e678e7ac src/lib-storage/index/index-storage.c --- 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) { diff -r e71256caeff9 -r b101e678e7ac src/lib-storage/index/index-storage.h --- 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); diff -r e71256caeff9 -r b101e678e7ac src/lib-storage/index/maildir/maildir-storage.c --- 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); diff -r e71256caeff9 -r b101e678e7ac src/lib-storage/index/mbox/mbox-storage.c --- 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);