]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit-reach: fix memory leak in `ahead_behind()`
authorPatrick Steinhardt <ps@pks.im>
Mon, 27 May 2024 11:46:54 +0000 (13:46 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 May 2024 18:20:01 +0000 (11:20 -0700)
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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit-reach.c
t/t3203-branch-output.sh

index 8f9b008f876787abf12ca89af5541f0b3bdf6ba7..384aee1ab3a3d9029e7d7281ccbd7515a5b7f2f7 100644 (file)
@@ -1106,6 +1106,10 @@ void ahead_behind(struct repository *r,
 
        /* STALE is used here, PARENT2 is used by insert_no_dup(). */
        repo_clear_commit_marks(r, PARENT2 | STALE);
+       while (prio_queue_peek(&queue)) {
+               struct commit *c = prio_queue_get(&queue);
+               free_bit_array(c);
+       }
        clear_bit_arrays(&bit_arrays);
        clear_prio_queue(&queue);
 }
index 758963b189d8d9fc7ad50f4fa06bf431c4fe6e80..e627f08a1790b39ea6d21d29cb769a8d58ceb580 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/sh
 
 test_description='git branch display tests'
+
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 . "$TEST_DIRECTORY"/lib-terminal.sh