@matheusbsbs / matheus-bagliano / commits / 6c7ff7cf7f
Fork 0

multi-pack-index: close file descriptor after mmap

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>

Derrick Stolee committed Apr 24, 2020 at 09:17 UTC 6c7ff7cf7f431e4accf360c018149d1e263eaf06
2 files changed +1 -5
midx.c
+1 -3
@@ -68,9 +68,9 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local
68 FREE_AND_NULL(midx_name);
69
70 midx_map = xmmap(NULL, midx_size, PROT_READ, MAP_PRIVATE, fd, 0);
71 + close(fd);
72
73 FLEX_ALLOC_MEM(m, object_dir, object_dir, strlen(object_dir));
73 - m->fd = fd;
74 m->data = midx_map;
75 m->data_len = midx_size;
76 m->local = local;
@@ -184,8 +184,6 @@ static void close_midx(struct multi_pack_index *m)
184 {
185 uint32_t i;
186 munmap((unsigned char *)m->data, m->data_len);
187 - close(m->fd);
188 - m->fd = -1;
187
188 for (i = 0; i < m->num_packs; i++) {
189 if (m->packs[i]) {
midx.h
-2
@@ -6,8 +6,6 @@
6 struct multi_pack_index {
7 struct multi_pack_index *next;
8
9 - int fd;
10 -
9 const unsigned char *data;
10 size_t data_len;
11