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

[PATCH v2 1/6] range-diff: avoid leaking memory in two error code paths

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Feb 5, 2021, 14:46 UTC
Message-ID
<15f4f6abdaa206ca9b89f4f2444b88a77ef1060c.1612536373.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.869.v2.git.1612536373.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

In the code paths in question, we already release a lot of memory, but the `current_filename` variable was missed. Fix that.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 range-diff.c | 2 ++
 1 file changed, 2 insertions(+)
diff --git a/range-diff.c b/range-diff.c
index 7a38dc871543..9972808fe4cf 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -98,6 +98,7 @@ static int read_patches(const char *range, struct string_list *list,
 			if (get_oid(p, &util->oid)) {
 				error(_("could not parse commit '%s'"), p);
 				free(util);
+				free(current_filename);
 				string_list_clear(list, 1);
 				strbuf_release(&buf);
 				strbuf_release(&contents);
@@ -113,6 +114,7 @@ static int read_patches(const char *range, struct string_list *list,
 			error(_("could not parse first line of `log` output: "
 				"did not start with 'commit ': '%s'"),
 			      line);
+			free(current_filename);
 			string_list_clear(list, 1);
 			strbuf_release(&buf);
 			strbuf_release(&contents);
-- 
gitgitgadget
Previous: Johannes Schindelin via GitGitGadgetNext: Johannes Schindelin via GitGitGadget
Message 21 of 22 in “Optionally restrict range-diff output to "left" or "right" range only”
  1. 0/6 Optionally restrict range-diff output to "left" or "right" range onlyJohannes Schindelin via GitGitGadget, Feb 4, 2021
  2. 3/6 range-diff: simplify code spawning `git log`Johannes Schindelin via GitGitGadget, Feb 4, 2021
  3. 1/6 range-diff: avoid leaking memory in two error code pathsJohannes Schindelin via GitGitGadget, Feb 4, 2021
  4. 2/6 range-diff: libify the read_patches() function againJohannes Schindelin via GitGitGadget, Feb 4, 2021
  5. 4/6 range-diff: combine all options in a single data structureJohannes Schindelin via GitGitGadget, Feb 4, 2021
  6. Eric SunshineFeb 4, 2021
  7. Johannes SchindelinFeb 5, 2021
  8. 6/6 range-diff: offer --left-only/--right-only optionsJohannes Schindelin via GitGitGadget, Feb 4, 2021
  9. 5/6 range-diff: move the diffopt initialization down one layerJohannes Schindelin via GitGitGadget, Feb 4, 2021
  10. Junio C HamanoFeb 4, 2021
  11. Taylor BlauFeb 4, 2021
  12. Junio C HamanoFeb 5, 2021
  13. Jeff KingFeb 5, 2021
  14. Johannes SchindelinFeb 8, 2021
  15. Taylor BlauFeb 5, 2021
  16. 0/6 Optionally restrict range-diff output to "left" or "right" range onlyJohannes Schindelin via GitGitGadget, Feb 5, 2021
  17. 3/6 range-diff: simplify code spawning `git log`Johannes Schindelin via GitGitGadget, Feb 5, 2021
  18. 5/6 range-diff: move the diffopt initialization down one layerJohannes Schindelin via GitGitGadget, Feb 5, 2021
  19. 2/6 range-diff: libify the read_patches() function againJohannes Schindelin via GitGitGadget, Feb 5, 2021
  20. 6/6 range-diff: offer --left-only/--right-only optionsJohannes Schindelin via GitGitGadget, Feb 5, 2021
  21. 1/6 range-diff: avoid leaking memory in two error code pathsJohannes Schindelin via GitGitGadget, Feb 5, 2021
  22. 4/6 range-diff: combine all options in a single data structureJohannes Schindelin via GitGitGadget, Feb 5, 2021

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.