From 83f28370062fb004397b399168eea778c24dc036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Onur=20G=C3=BCnd=C3=BCz?= Date: Wed, 25 Nov 2026 13:34:06 +0100 Subject: [PATCH] refs/debug: free the wrapped ref iterator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- 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 639db0f26e1bbb..96bf9d55d30bba 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 6d8f401a2a9827..e414b61c10df00 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 &&