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

Re: [PATCH] sequencer: fix memory leak if `update_squash_messages()` failed

From
lidongyan <502024330056@smail.nju.edu.cn>
Date
May 15, 2025, 16:43 UTC
Message-ID
<AD5588EE-C935-42E8-9876-F47FB35309D9@smail.nju.edu.cn>
In-Reply-To
<xmqqldqx3ky7.fsf@gitster.g>
2025年5月16日 00:20,Junio C Hamano <gitster@pobox.com> 写道:
Show 29 quoted lines
> 
> I am curious if Lidong's tool would notice an unreachable code if
> only the first hunk of the attached patch is applied.  The "else"
> clause in the second hunk would become unreachable.
> 
> 
> diff --git c/sequencer.c w/sequencer.c
> index b5c4043757..269637d427 100644
> --- c/sequencer.c
> +++ w/sequencer.c
> @@ -2071,6 +2071,9 @@ static int update_squash_messages(struct repository *r,
> const char *message, *body;
> const char *encoding = get_commit_output_encoding();
> 
> + if (!(command == TODO_FIXUP || command == TODO_SQUASH))
> + BUG("update_squash_messages with command %d", command);
> +
> if (ctx->current_fixup_count > 0) {
> struct strbuf header = STRBUF_INIT;
> char *eol;
> @@ -2138,8 +2141,6 @@ static int update_squash_messages(struct repository *r,
> strbuf_addstr(&buf, "\n\n");
> strbuf_add_commented_lines(&buf, body, strlen(body),
>   comment_line_str);
> - } else
> - return error(_("unknown command: %d"), command);
> repo_unuse_commit_buffer(r, commit, message);
> 
> if (!res)

In this case, we do not directly identify the else branch as unreachable code. However, we perform constraint solving on the conditions leading to a potential leak, which ultimately allows us to determine that the leaking path is actually unreachable.

Previous: Junio C HamanoNext: Lidong Yan via GitGitGadget
Message 4 of 18 in “sequencer: fix memory leak if `update_squash_messages()` failed”
  1. sequencer: fix memory leak if `update_squash_messages()` failedLidong Yan via GitGitGadget, May 14, 2025
  2. Phillip WoodMay 15, 2025
  3. Junio C HamanoMay 15, 2025
  4. lidongyanMay 15, 2025
  5. sequencer: replace error() with BUG() in update_squash_messages()Lidong Yan via GitGitGadget, May 25, 2025
  6. Junio C HamanoMay 28, 2025
  7. Phillip WoodMay 29, 2025
  8. Junio C HamanoMay 30, 2025
  9. Phillip WoodJun 2, 2025
  10. 0/2 sequencer: replace error() with BUG() in update_squash_messages()Lidong Yan via GitGitGadget, May 30, 2025
  11. 1/2 sequencer: replace error() with BUG() in update_squash_messages()Lidong Yan via GitGitGadget, May 30, 2025
  12. Junio C HamanoMay 30, 2025
  13. 2/2 BUG(): remove leading underscore of the format stringLidong Yan via GitGitGadget, May 30, 2025
  14. Junio C HamanoMay 30, 2025
  15. 0/2 sequencer: replace error() with BUG() in update_squash_messages()Lidong Yan via GitGitGadget, Jun 3, 2025
  16. 1/2 sequencer: replace error() with BUG() in update_squash_messages()Lidong Yan via GitGitGadget, Jun 3, 2025
  17. 2/2 BUG(): remove leading underscore of the format stringLidong Yan via GitGitGadget, Jun 3, 2025
  18. Junio C HamanoJun 3, 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.