Skip to content

Commit 6f1e939

Browse files
pks-tgitster
authored andcommitted
object: fix leaking packfiles when closing object store
When calling `raw_object_store_clear()`, we close and free several resources associated with the object store. Part of that is to close and free all the packfiles, which is handled by `close_object_store()`. That function really only ends up closing the packfiles though, but it doesn't free them. And in fact it can't, as that function is being called via `run_command()` when `close_object_store = 1`, which is done e.g. when we execute git-maintenance(1). At that point, other structures may still have references on those packfiles, and thus we cannot free them here. So while it is in fact intentional that we really only close them, the result is a memory leak because `raw_object_store_clear()` does not free them, either. Fix the leak by freeing the packfiles in `raw_object_store_clear()`. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fa0f27a commit 6f1e939

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

object.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,15 @@ void raw_object_store_clear(struct raw_object_store *o)
614614

615615
INIT_LIST_HEAD(&o->packed_git_mru);
616616
close_object_store(o);
617+
618+
/*
619+
* `close_object_store()` only closes the packfiles, but doesn't free
620+
* them. We thus have to do this manually.
621+
*/
622+
for (struct packed_git *p = o->packed_git, *next; p; p = next) {
623+
next = p->next;
624+
free(p);
625+
}
617626
o->packed_git = NULL;
618627

619628
hashmap_clear(&o->pack_map);

t/t7424-submodule-mixed-ref-formats.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='submodules handle mixed ref storage formats'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./test-lib.sh
67

78
test_ref_format () {

0 commit comments

Comments
 (0)