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

[PATCH v2 3/4] add-patch: plug a leak handling the '/' command

From
Rubén Justo <rjusto@gmail.com>
Date
Apr 22, 2024, 22:54 UTC
Message-ID
<f35a22a9-bbb1-491c-9f1f-e8c77f18fb9f@gmail.com>
In-Reply-To
<69f86760-96ff-4c62-9649-4627652b7c19@gmail.com>

Plug a leak we have since d6cf873340 (built-in add -p: implement the '/' ("search regex") command, 2019-12-13).

This leak can be triggered with:
    $ printf "A\n\nB\n" >file
    $ git add file && git commit -m file
    $ printf "AA\n\nBB\n" >file
    $ printf "s\n/ .\n" >lines
    $ git add -p <lines
Signed-off-by: Rubén Justo <rjusto@gmail.com>
---
 add-patch.c | 1 +
 1 file changed, 1 insertion(+)
diff --git a/add-patch.c b/add-patch.c
index a06dd18985..0997d4af73 100644
--- a/add-patch.c
+++ b/add-patch.c
@@ -1646,6 +1646,7 @@ static int patch_update_file(struct add_p_state *s,
 				err(s, _("No hunk matches the given pattern"));
 				break;
 			}
+			regfree(&regex);
 			hunk_index = i;
 		} else if (s->answer.buf[0] == 's') {
 			size_t splittable_into = hunk->splittable_into;
-- 
2.45.0.rc0.4.gfff7e48949
Previous: Rubén JustoNext: Rubén Justo
Message 17 of 19 in “mark t3701-add-interactive.sh as leak-free”
  1. 0/4 mark t3701-add-interactive.sh as leak-freeRubén Justo, Apr 21, 2024
  2. 2/4 add-interactive: plug a leak in get_untracked_filesRubén Justo, Apr 21, 2024
  3. Junio C HamanoApr 22, 2024
  4. 1/4 apply: plug a leak in apply_dataRubén Justo, Apr 21, 2024
  5. Phillip WoodApr 22, 2024
  6. Rubén JustoApr 22, 2024
  7. Junio C HamanoApr 22, 2024
  8. 3/4 add-patch: plug a leak handling the '/' commandRubén Justo, Apr 21, 2024
  9. 4/4 add: plug a leak on interactive_addRubén Justo, Apr 21, 2024
  10. Phillip WoodApr 22, 2024
  11. Rubén JustoApr 22, 2024
  12. Patrick SteinhardtApr 22, 2024
  13. Junio C HamanoApr 22, 2024
  14. 0/4 mark t3701-add-interactive.sh as leak-freeRubén Justo, Apr 22, 2024
  15. 1/4 apply: plug a leak in apply_dataRubén Justo, Apr 22, 2024
  16. 2/4 add-interactive: plug a leak in get_untracked_filesRubén Justo, Apr 22, 2024
  17. 3/4 add-patch: plug a leak handling the '/' commandRubén Justo, Apr 22, 2024
  18. 4/4 add: plug a leak on interactive_addRubén Justo, Apr 22, 2024
  19. Junio C HamanoApr 22, 2024

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.