git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [BUG] rebase: can write reflog with uninit. `action` string

From
Junio C Hamano <gitster@pobox.com>
Date
May 1, 2025, 16:07 UTC
Message-ID
<xmqq4iy4z55h.fsf@gitster.g>
In-Reply-To
<20250501131751.GA1725607@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 9 quoted lines
> Probably the smallest solution is for ctx->reflog_message to copy the
> result and always own the memory (and then remember to free it, both at
> cleanup and if it is ever overwritten).
>
> But I think the way reflog_message() returns the "buf" member of a
> static strbuf is kind of an anti-pattern, exactly because you can get
> this kind of subtle re-use. It probably should just return a non-const
> pointer, handing over memory ownership to the caller. That would require
> adjusting its other callers, too.

Yeah, yesterday I was looking at the same report and was thinking that the memory ownership model here is somewhat screwed up. As a few more allocations/deallocations should be dwarfed by the real processing cost of replaying each commit, I think this "smallest" solution is also the solution in the right direction.

> So the "smallest" version is perhaps something like this, totally
> untested except for confirming that t3430 no longer complains:
;-)
>  	va_start(ap, fmt);
> -	strbuf_reset(&buf);
> +	strbuf_release(&buf); /* guarantees realloaction */

I initially thought that this comment may have to be updated in the production version, but because we have to freshly allocate for each new message for ownership change, this comment still is correct. The only difference between the "here is how to expose" and "this is part of the smallest solution" is why we want to guarantee it.

> I'm hoping your or Phillip can decide on the best fix from here.
;-)
Previous: Jeff KingNext: Jeff King
Message 9 of 12 in “[BUG] rebase: can write reflog with uninit. `action` string”
  1. Kristoffer HaugsbakkApr 28, 2025
  2. Phillip WoodApr 29, 2025
  3. Kristoffer HaugsbakkApr 29, 2025
  4. Jeff KingApr 29, 2025
  5. Kristoffer HaugsbakkApr 30, 2025
  6. Jeff KingMay 1, 2025
  7. phillip.wood123@gmail.comMay 1, 2025
  8. Jeff KingMay 1, 2025
  9. Junio C HamanoMay 1, 2025
  10. Jeff KingMay 1, 2025
  11. Junio C HamanoMay 1, 2025
  12. phillip.wood123@gmail.comMay 1, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.