summaryrefslogtreecommitdiff
path: root/midx.c
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2018-10-12 10:34:19 -0700
committerJunio C Hamano <gitster@pobox.com>2018-10-22 10:42:46 +0900
commit1dcd9f2043a38f0c9684d47c71b9e383942660ac (patch)
treeccc137d372ff6f1d4a6285f7448ac7f5e465eba3 /midx.c
parent0ce4ff942125eabed3df694dc27922bec8177624 (diff)
downloadgit-1dcd9f2043a38f0c9684d47c71b9e383942660ac.tar.gz
midx: close multi-pack-index on repack
When repacking, we may remove pack-files. This invalidates the multi-pack-index (if it exists). Previously, we removed the multi-pack-index file before removing any pack-file. In some cases, the repack command may load the multi-pack-index into memory. This may lead to later in-memory references to the non-existent pack- files. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'midx.c')
-rw-r--r--midx.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/midx.c b/midx.c
index 999717b96f..2243c912fc 100644
--- a/midx.c
+++ b/midx.c
@@ -180,9 +180,13 @@ cleanup_fail:
return NULL;
}
-static void close_midx(struct multi_pack_index *m)
+void close_midx(struct multi_pack_index *m)
{
uint32_t i;
+
+ if (!m)
+ return;
+
munmap((unsigned char *)m->data, m->data_len);
close(m->fd);
m->fd = -1;
@@ -917,9 +921,14 @@ cleanup:
return 0;
}
-void clear_midx_file(const char *object_dir)
+void clear_midx_file(struct repository *r)
{
- char *midx = get_midx_filename(object_dir);
+ char *midx = get_midx_filename(r->objects->objectdir);
+
+ if (r->objects && r->objects->multi_pack_index) {
+ close_midx(r->objects->multi_pack_index);
+ r->objects->multi_pack_index = NULL;
+ }
if (remove_path(midx)) {
UNLEAK(midx);