From: Derrick Stolee <dstolee@xxxxxxxxxxxxx> 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@xxxxxxxxxxxxx> --- builtin/repack.c | 4 ++++ midx.c | 6 +++++- midx.h | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/builtin/repack.c b/builtin/repack.c index c6a7943d5c..7925bb976e 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -432,6 +432,10 @@ int cmd_repack(int argc, const char **argv, const char *prefix) if (!midx_cleared) { /* if we move a packfile, it will invalidated the midx */ + if (the_repository->objects) { + close_midx(the_repository->objects->multi_pack_index); + the_repository->objects->multi_pack_index = NULL; + } clear_midx_file(get_object_directory()); midx_cleared = 1; } diff --git a/midx.c b/midx.c index 999717b96f..fe8532a9d1 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; diff --git a/midx.h b/midx.h index a210f1af2a..af6b5cb58f 100644 --- a/midx.h +++ b/midx.h @@ -44,4 +44,6 @@ int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, i int write_midx_file(const char *object_dir); void clear_midx_file(const char *object_dir); +void close_midx(struct multi_pack_index *m); + #endif -- gitgitgadget