* [PATCH] refs/debug: free the wrapped ref iterator
@ 2026-11-26 3:37 Onur Gündüz via GitGitGadget
2026-12-01 15:19 ` Patrick Steinhardt
0 siblings, 1 reply; 2+ messages in thread
From: Onur Gündüz via GitGitGadget @ 2026-11-26 3:37 UTC (permalink / raw)
To: git; +Cc: Onur Gündüz, Onur Gündüz
From: =?UTF-8?q?Onur=20G=C3=BCnd=C3=BCz?= <ogunduz@gmail.com>
Commit cec2b6f55a (refs/iterator: separate lifecycle from iteration,
2025-03-12) moved deallocation of ref iterators from the backend
callbacks to ref_iterator_free(). However, the debug iterator still
calls the wrapped iterator's release callback directly. This frees
its backend-specific resources but leaks the iterator itself.
Call ref_iterator_free() instead so that both the resources and the
wrapped iterator are freed.
Add a test that compares reference iteration with tracing enabled
and disabled. Without the fix, the traced invocation leaks under
LeakSanitizer with both the files and reftable backends.
Signed-off-by: Onur Gündüz <ogunduz@gmail.com>
---
refs/debug: free the wrapped ref iterator
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2332%2Ftetsuo%2Fsubmit%2Frefs-debug-iterator-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2332/tetsuo/submit/refs-debug-iterator-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2332
refs/debug.c | 2 +-
t/t1405-main-ref-store.sh | 6 ++++++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/refs/debug.c b/refs/debug.c
index 639db0f26e..96bf9d55d3 100644
--- a/refs/debug.c
+++ b/refs/debug.c
@@ -200,7 +200,7 @@ static void debug_ref_iterator_release(struct ref_iterator *ref_iterator)
{
struct debug_ref_iterator *diter =
(struct debug_ref_iterator *)ref_iterator;
- diter->iter->vtable->release(diter->iter);
+ ref_iterator_free(diter->iter);
trace_printf_key(&trace_refs, "iterator_abort\n");
}
diff --git a/t/t1405-main-ref-store.sh b/t/t1405-main-ref-store.sh
index 6d8f401a2a..e414b61c10 100755
--- a/t/t1405-main-ref-store.sh
+++ b/t/t1405-main-ref-store.sh
@@ -55,6 +55,12 @@ test_expect_success 'for_each_ref() is sorted' '
test_cmp expected actual
'
+test_expect_success 'for_each_ref() with tracing' '
+ $RUN for-each-ref refs/heads/ >expected &&
+ GIT_TRACE_REFS=1 $RUN for-each-ref refs/heads/ >actual &&
+ test_cmp expected actual
+'
+
test_expect_success 'resolve_ref(new-main)' '
SHA1=`git rev-parse new-main` &&
echo "$SHA1 refs/heads/new-main 0x0" >expected &&
base-commit: 03b41523c576f26ad34085378717a0c1b287470f
--
gitgitgadget
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] refs/debug: free the wrapped ref iterator
2026-11-26 3:37 [PATCH] refs/debug: free the wrapped ref iterator Onur Gündüz via GitGitGadget
@ 2026-12-01 15:19 ` Patrick Steinhardt
0 siblings, 0 replies; 2+ messages in thread
From: Patrick Steinhardt @ 2026-12-01 15:19 UTC (permalink / raw)
To: Onur Gündüz via GitGitGadget; +Cc: git, Onur Gündüz
On Thu, Nov 26, 2026 at 03:37:43AM +0000, Onur Gündüz via GitGitGadget wrote:
> diff --git a/refs/debug.c b/refs/debug.c
> index 639db0f26e..96bf9d55d3 100644
> --- a/refs/debug.c
> +++ b/refs/debug.c
> @@ -200,7 +200,7 @@ static void debug_ref_iterator_release(struct ref_iterator *ref_iterator)
> {
> struct debug_ref_iterator *diter =
> (struct debug_ref_iterator *)ref_iterator;
> - diter->iter->vtable->release(diter->iter);
> + ref_iterator_free(diter->iter);
> trace_printf_key(&trace_refs, "iterator_abort\n");
> }
Do we maybe want to also NULL `diter->iter` to not leave the pointer
dangling? In theory that shouldn't ever be a problem as we'd free the
debug ref iterator, anyway. But it might make sense to do it regardless.
> diff --git a/t/t1405-main-ref-store.sh b/t/t1405-main-ref-store.sh
> index 6d8f401a2a..e414b61c10 100755
> --- a/t/t1405-main-ref-store.sh
> +++ b/t/t1405-main-ref-store.sh
> @@ -55,6 +55,12 @@ test_expect_success 'for_each_ref() is sorted' '
> test_cmp expected actual
> '
>
> +test_expect_success 'for_each_ref() with tracing' '
> + $RUN for-each-ref refs/heads/ >expected &&
> + GIT_TRACE_REFS=1 $RUN for-each-ref refs/heads/ >actual &&
> + test_cmp expected actual
> +'
This would of course succeed without the patch without leak sanitizer,
but our CI also runs with leak sanitizer. So this test is good enough.
Do we maybe want to verify that `GIT_TRACE_REFS` does anything by also
redirecting stderr and then doing something like `test_grep
iterator_advance`?
Thanks!
Patrick
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-01 15:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 3:37 [PATCH] refs/debug: free the wrapped ref iterator Onur Gündüz via GitGitGadget
2026-12-01 15:19 ` Patrick Steinhardt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox