{"thread":{"id":"66937","subject":"[PATCH] refs/debug: free the wrapped ref iterator","startedAt":"2026-11-26T03:37:43Z","lastAt":"2026-12-01T15:19:11Z","messageCount":2,"participants":["Onur Gündüz via GitGitGadget","Patrick Steinhardt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"559434","messageId":"pull.2332.git.1795664263318.gitgitgadget@gmail.com","threadId":"66937","inReplyTo":null,"subject":"[PATCH] refs/debug: free the wrapped ref iterator","fromName":"Onur Gündüz via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-26T03:37:43Z","receivedAt":"2026-11-26T03:37:43Z","isPatch":true,"sender":{"key":"name:Onur Gündüz","avatar":null},"body":"From: =?UTF-8?q?Onur=20G=C3=BCnd=C3=BCz?= <ogunduz@gmail.com>\n\nCommit cec2b6f55a (refs/iterator: separate lifecycle from iteration,\n2025-03-12) moved deallocation of ref iterators from the backend\ncallbacks to ref_iterator_free(). However, the debug iterator still\ncalls the wrapped iterator's release callback directly. This frees\nits backend-specific resources but leaks the iterator itself.\n\nCall ref_iterator_free() instead so that both the resources and the\nwrapped iterator are freed.\n\nAdd a test that compares reference iteration with tracing enabled\nand disabled. Without the fix, the traced invocation leaks under\nLeakSanitizer with both the files and reftable backends.\n\nSigned-off-by: Onur Gündüz <ogunduz@gmail.com>\n---\n    refs/debug: free the wrapped ref iterator\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2332%2Ftetsuo%2Fsubmit%2Frefs-debug-iterator-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2332/tetsuo/submit/refs-debug-iterator-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/2332\n\n refs/debug.c              | 2 +-\n t/t1405-main-ref-store.sh | 6 ++++++\n 2 files changed, 7 insertions(+), 1 deletion(-)\n\ndiff --git a/refs/debug.c b/refs/debug.c\nindex 639db0f26e..96bf9d55d3 100644\n--- a/refs/debug.c\n+++ b/refs/debug.c\n@@ -200,7 +200,7 @@ static void debug_ref_iterator_release(struct ref_iterator *ref_iterator)\n {\n \tstruct debug_ref_iterator *diter =\n \t\t(struct debug_ref_iterator *)ref_iterator;\n-\tditer->iter->vtable->release(diter->iter);\n+\tref_iterator_free(diter->iter);\n \ttrace_printf_key(&trace_refs, \"iterator_abort\\n\");\n }\n \ndiff --git a/t/t1405-main-ref-store.sh b/t/t1405-main-ref-store.sh\nindex 6d8f401a2a..e414b61c10 100755\n--- a/t/t1405-main-ref-store.sh\n+++ b/t/t1405-main-ref-store.sh\n@@ -55,6 +55,12 @@ test_expect_success 'for_each_ref() is sorted' '\n \ttest_cmp expected actual\n '\n \n+test_expect_success 'for_each_ref() with tracing' '\n+\t$RUN for-each-ref refs/heads/ >expected &&\n+\tGIT_TRACE_REFS=1 $RUN for-each-ref refs/heads/ >actual &&\n+\ttest_cmp expected actual\n+'\n+\n test_expect_success 'resolve_ref(new-main)' '\n \tSHA1=`git rev-parse new-main` &&\n \techo \"$SHA1 refs/heads/new-main 0x0\" >expected &&\n\nbase-commit: 03b41523c576f26ad34085378717a0c1b287470f\n-- \ngitgitgadget\n\n"},{"id":"559802","messageId":"aw7lb299-Z2Hb_uY@pks.im","threadId":"66937","inReplyTo":"pull.2332.git.1795664263318.gitgitgadget@gmail.com","subject":"Re: [PATCH] refs/debug: free the wrapped ref iterator","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-12-01T15:19:11Z","receivedAt":"2026-12-01T15:19:11Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Nov 26, 2026 at 03:37:43AM +0000, Onur Gündüz via GitGitGadget wrote:\n> diff --git a/refs/debug.c b/refs/debug.c\n> index 639db0f26e..96bf9d55d3 100644\n> --- a/refs/debug.c\n> +++ b/refs/debug.c\n> @@ -200,7 +200,7 @@ static void debug_ref_iterator_release(struct ref_iterator *ref_iterator)\n>  {\n>  \tstruct debug_ref_iterator *diter =\n>  \t\t(struct debug_ref_iterator *)ref_iterator;\n> -\tditer->iter->vtable->release(diter->iter);\n> +\tref_iterator_free(diter->iter);\n>  \ttrace_printf_key(&trace_refs, \"iterator_abort\\n\");\n>  }\n\nDo we maybe want to also NULL `diter->iter` to not leave the pointer\ndangling? In theory that shouldn't ever be a problem as we'd free the\ndebug ref iterator, anyway. But it might make sense to do it regardless.\n\n> diff --git a/t/t1405-main-ref-store.sh b/t/t1405-main-ref-store.sh\n> index 6d8f401a2a..e414b61c10 100755\n> --- a/t/t1405-main-ref-store.sh\n> +++ b/t/t1405-main-ref-store.sh\n> @@ -55,6 +55,12 @@ test_expect_success 'for_each_ref() is sorted' '\n>  \ttest_cmp expected actual\n>  '\n>  \n> +test_expect_success 'for_each_ref() with tracing' '\n> +\t$RUN for-each-ref refs/heads/ >expected &&\n> +\tGIT_TRACE_REFS=1 $RUN for-each-ref refs/heads/ >actual &&\n> +\ttest_cmp expected actual\n> +'\n\nThis would of course succeed without the patch without leak sanitizer,\nbut our CI also runs with leak sanitizer. So this test is good enough.\n\nDo we maybe want to verify that `GIT_TRACE_REFS` does anything by also\nredirecting stderr and then doing something like `test_grep\niterator_advance`?\n\nThanks!\n\nPatrick\n\n"}]}