]> git.ipfire.org Git - thirdparty/git.git/commitdiff
multi-pack-index: close file descriptor after mmap
authorDerrick Stolee <stolee@gmail.com>
Fri, 24 Apr 2020 13:17:16 +0000 (09:17 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 24 Apr 2020 20:09:49 +0000 (13:09 -0700)
The multi-pack-index subsystem was not closing its file descriptor
after memory-mapping the file contents. After this mmap() succeeds,
there is no need to keep the file descriptor open.  In fact, there
is signficant reason to close it so we do not run out of
descriptors.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
midx.c
midx.h

diff --git a/midx.c b/midx.c
index f3e8dbc10820303436c07126b85d6024d2fb3e56..95d29ce4629e093af78f0bbfd2275563bdb3c3b1 100644 (file)
--- a/midx.c
+++ b/midx.c
@@ -68,9 +68,9 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local
        FREE_AND_NULL(midx_name);
 
        midx_map = xmmap(NULL, midx_size, PROT_READ, MAP_PRIVATE, fd, 0);
+       close(fd);
 
        FLEX_ALLOC_MEM(m, object_dir, object_dir, strlen(object_dir));
-       m->fd = fd;
        m->data = midx_map;
        m->data_len = midx_size;
        m->local = local;
@@ -184,8 +184,6 @@ static void close_midx(struct multi_pack_index *m)
 {
        uint32_t i;
        munmap((unsigned char *)m->data, m->data_len);
-       close(m->fd);
-       m->fd = -1;
 
        for (i = 0; i < m->num_packs; i++) {
                if (m->packs[i]) {
diff --git a/midx.h b/midx.h
index a210f1af2af6bd7c7dc2210ac4b5ca398c8c60d1..33c36ae19b09b77daa47f7ac2ae583c5dc5d749e 100644 (file)
--- a/midx.h
+++ b/midx.h
@@ -6,8 +6,6 @@
 struct multi_pack_index {
        struct multi_pack_index *next;
 
-       int fd;
-
        const unsigned char *data;
        size_t data_len;