From: Patrick Steinhardt <ps@pks.im>
To: Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>
Cc: git@vger.kernel.org, Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Subject: Re: history: 'reword HEAD' surfaces a memory leak
Date: Mon, 7 Sep 2026 13:13:23 +0200 [thread overview]
Message-ID: <ap6cU2elXvmlLgb8@pks.im> (raw)
In-Reply-To: <04faa984-5b56-406b-baa9-dbb4b5eab259@app.fastmail.com>
On Thu, Sep 03, 2026 at 05:26:44PM +0200, Kristoffer Haugsbakk wrote:
> I get a sanitizer error when I run a simple reword command:
>
> $ make SANITIZE=address install
> $ GIT_EDITOR=true git history reword \
> --dry-run 3cb9185f65410273787f74333cc027d2ea5daada
> update HEAD eeb9d4b5c4041739c0a19b4043924513c8aad2d2 3cb9185f65410273787f74333cc027d2ea5daada
>
> =================================================================
> ==116999==ERROR: LeakSanitizer: detected memory leaks
>
> Direct leak of 283 byte(s) in 1 object(s) allocated from:
> #0 0x712d2f6b4887 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
> #1 0x61970a5757b2 in do_xmalloc /home/kristoffer/programming/git-worktree/git-leakcheck/wrapper.c:55
> #2 0x61970a575ec0 in do_xmallocz /home/kristoffer/programming/git-worktree/git-leakcheck/wrapper.c:89
> #3 0x61970a575ec0 in do_xmallocz /home/kristoffer/programming/git-worktree/git-leakcheck/wrapper.c:79
> #4 0x61970a575ec0 in xmallocz_gently /home/kristoffer/programming/git-worktree/git-leakcheck/wrapper.c:102
> #5 0x61970a309ca0 in unpack_compressed_entry /home/kristoffer/programming/git-worktree/git-leakcheck/packfile.c:1732
> #6 0x61970a310bf0 in unpack_entry /home/kristoffer/programming/git-worktree/git-leakcheck/packfile.c:1885
> #7 0x61970a311fbf in cache_or_unpack_entry /home/kristoffer/programming/git-worktree/git-leakcheck/packfile.c:1528
> #8 0x61970a311fbf in packed_object_info_with_index_pos /home/kristoffer/programming/git-worktree/git-leakcheck/packfile.c:1610
> #9 0x61970a313097 in packed_object_info /home/kristoffer/programming/git-worktree/git-leakcheck/packfile.c:1720
> #10 0x61970a313097 in packfile_store_read_object_info /home/kristoffer/programming/git-worktree/git-leakcheck/packfile.c:2214
> #11 0x61970a2caae8 in odb_source_files_read_object_info odb/source-files.c:58
> #12 0x61970a2c69a7 in odb_source_read_object_info odb/source.h:326
> #13 0x61970a2c69a7 in do_oid_object_info_extended /home/kristoffer/programming/git-worktree/git-leakcheck/odb.c:572
> #14 0x61970a2c69a7 in odb_read_object_info_extended /home/kristoffer/programming/git-worktree/git-leakcheck/odb.c:710
> #15 0x61970a2c7cbe in odb_read_object /home/kristoffer/programming/git-worktree/git-leakcheck/odb.c:756
> #16 0x61970a101d5a in repo_get_commit_buffer /home/kristoffer/programming/git-worktree/git-leakcheck/commit.c:399
> #17 0x61970a101d5a in repo_get_commit_buffer /home/kristoffer/programming/git-worktree/git-leakcheck/commit.c:391
> #18 0x61970a346bf6 in repo_logmsg_reencode /home/kristoffer/programming/git-worktree/git-leakcheck/pretty.c:716
> #19 0x619709ebbe64 in commit_tree_ext builtin/history.c:127
> #20 0x619709ebd17f in commit_tree_with_edited_message builtin/history.c:183
> #21 0x619709ebd17f in cmd_history_reword builtin/history.c:717
> #22 0x619709ec186f in cmd_history builtin/history.c:998
> #23 0x619709d87ca0 in run_builtin /home/kristoffer/programming/git-worktree/git-leakcheck/git.c:506
> #24 0x619709d87ca0 in handle_builtin /home/kristoffer/programming/git-worktree/git-leakcheck/git.c:782
> #25 0x619709d8c9a6 in run_argv /home/kristoffer/programming/git-worktree/git-leakcheck/git.c:865
> #26 0x619709d8c9a6 in cmd_main /home/kristoffer/programming/git-worktree/git-leakcheck/git.c:986
> #27 0x619709d83f54 in main /home/kristoffer/programming/git-worktree/git-leakcheck/common-main.c:9
> #28 0x712d2f229d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
>
> SUMMARY: AddressSanitizer: 283 byte(s) leaked in 1 allocation(s).
This feels familiar, even though it doesn't reproduce on my machine. Do
you have "i18n.commitencoding" set? In any case, I think the following
patch should fix it:
diff --git a/builtin/history.c b/builtin/history.c
index 000155ad9c..bca95b9d05 100644
--- a/builtin/history.c
+++ b/builtin/history.c
@@ -158,6 +158,7 @@ static int commit_tree_ext(struct repository *repo,
*out = lookup_commit_or_die(&rewritten_commit_oid, "rewritten commit");
out:
+ repo_unuse_commit_buffer(repo, commit_with_message, original_message);
free_commit_extra_headers(original_extra_headers);
strbuf_release(&commit_message);
free(original_author);
I know that we've already been discussing this memory leak on the
mailing list at one point in time, and we've already had a patch similar
to the above. So why wasn't this merged...?
Ah, the discussion was in [1]. Cc'ing Kaartic.
Thanks!
Patrick
[1]: https://lore.kernel.org/git/20260614141600.620272-1-kaartic.sivaraam@gmail.com/
next prev parent reply other threads:[~2026-09-07 11:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 15:26 history: 'reword HEAD' surfaces a memory leak Kristoffer Haugsbakk
2026-09-07 11:13 ` Patrick Steinhardt [this message]
2026-09-07 11:46 ` Kaartic Sivaraam
2026-09-07 12:12 ` Patrick Steinhardt
2026-09-10 15:27 ` Kristoffer Haugsbakk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ap6cU2elXvmlLgb8@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=kaartic.sivaraam@gmail.com \
--cc=kristofferhaugsbakk@fastmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.