]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Fixes memory/fd leaking with INDEX=MEMORY.
authorTimo Sirainen <tss@iki.fi>
Tue, 23 Sep 2003 19:34:34 +0000 (22:34 +0300)
committerTimo Sirainen <tss@iki.fi>
Tue, 23 Sep 2003 19:34:34 +0000 (22:34 +0300)
--HG--
branch : HEAD

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

index f805cdb5dd7a3abbe72e5dfe4913a14993e3ba8d..761d0d9f24bfbc76e511e45f69252c0189090b56 100644 (file)
@@ -57,27 +57,31 @@ void index_storage_add(struct mail_index *index)
        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) {
index 94620237b7417ce1c6b62fb36927a7733f57f037..eba3509bb4414095de8c97bddf191522e1388835 100644 (file)
@@ -55,7 +55,8 @@ int index_storage_lock(struct index_mailbox *ibox,
                       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);
 
index ab53dd306c164993c6b0844264eee7edffb00969..5617791652f16cc9bb7a17230c1433fbf9610b89 100644 (file)
@@ -397,7 +397,7 @@ maildir_open(struct mail_storage *storage, const char *name,
        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);
index 80dfe93d0ab2b067b547acd1c06a65a86cebf601..7bb614aa2a5fe617df5174d64f45ed94499b85f6 100644 (file)
@@ -393,7 +393,7 @@ static struct mailbox *mbox_open(struct mail_storage *storage, const char *name,
                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);