Skip to content

Commit ba9d029

Browse files
pks-tgitster
authored andcommitted
commit-reach: fix memory leak in ahead_behind()
We use a priority queue in `ahead_behind()` to compute the ahead/behind count for commits. We may not iterate through all commits part of that queue though in case all of its entries are stale. Consequently, as we never make the effort to release the remaining commits, we end up leaking bit arrays that we have allocated for each of the contained commits. Plug this leak and mark the corresponding test as leak free. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 96c1655 commit ba9d029

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

commit-reach.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,10 @@ void ahead_behind(struct repository *r,
11061106

11071107
/* STALE is used here, PARENT2 is used by insert_no_dup(). */
11081108
repo_clear_commit_marks(r, PARENT2 | STALE);
1109+
while (prio_queue_peek(&queue)) {
1110+
struct commit *c = prio_queue_get(&queue);
1111+
free_bit_array(c);
1112+
}
11091113
clear_bit_arrays(&bit_arrays);
11101114
clear_prio_queue(&queue);
11111115
}

t/t3203-branch-output.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22

33
test_description='git branch display tests'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
46
. ./test-lib.sh
57
. "$TEST_DIRECTORY"/lib-terminal.sh
68

0 commit comments

Comments
 (0)