From b1fd23837e30cfc10fcbd2236eb1f35c91ec2093 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 27 May 2019 11:17:35 +0200 Subject: [PATCH] fixup! multi-pack-index: implement 'expire' verb When we close a pack, it might still be in the Most-Recently-Used list. If we truly want to remove it (and release its memory), we have to remove it from that list first. This fixes a complaint by valgrind, and a segmentation fault on Windows (where nedmalloc stumbles right over the overwritten memory). Signed-off-by: Johannes Schindelin --- midx.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/midx.c b/midx.c index ffc1a16f0095f1..170c89ae1360b2 100644 --- a/midx.c +++ b/midx.c @@ -1165,6 +1165,15 @@ int expire_midx_packs(const char *object_dir) if (m->packs[i]->pack_keep) continue; + if (r->objects->packed_git_mru.prev == &m->packs[i]->mru) + r->objects->packed_git_mru.prev = m->packs[i]->mru.prev; + if (r->objects->packed_git_mru.next == &m->packs[i]->mru) + r->objects->packed_git_mru.next = m->packs[i]->mru.next; + if (m->packs[i]->mru.next) + m->packs[i]->mru.next->prev = m->packs[i]->mru.prev; + if (m->packs[i]->mru.prev) + m->packs[i]->mru.prev->next = m->packs[i]->mru.next; + pack_name = xstrdup(m->packs[i]->pack_name); close_pack(m->packs[i]); FREE_AND_NULL(m->packs[i]);