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

[PATCH 01/13] load_one_loose_object_map(): fix resource leak

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Jul 1, 2026, 07:04 UTC
Message-ID
<17242c249f0beb387fd30634663f13ce42d34f79.1782889472.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2163.git.1782889472.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>
Pointed out by Coverity.

While at it, reduce near-duplicate clean-up code at the end of the function.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 loose.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/loose.c b/loose.c
index 0b626c1b85..47b7f5ec38 100644
--- a/loose.c
+++ b/loose.c
@@ -65,6 +65,7 @@ static int load_one_loose_object_map(struct repository *repo, struct odb_source_
 {
 	struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
 	FILE *fp;
+	int ret = -1;
 
 	if (!loose->map)
 		loose_object_map_init(&loose->map);
@@ -98,13 +99,12 @@ static int load_one_loose_object_map(struct repository *repo, struct odb_source_
 		insert_loose_map(loose, &oid, &compat_oid);
 	}
 
-	strbuf_release(&buf);
-	strbuf_release(&path);
-	return errno ? -1 : 0;
+	ret = 0;
 err:
+	fclose(fp);
 	strbuf_release(&buf);
 	strbuf_release(&path);
-	return -1;
+	return ret;
 }
 
 int repo_read_loose_object_map(struct repository *repo)
-- 
gitgitgadget
Previous: Johannes Schindelin via GitGitGadgetNext: Patrick Steinhardt
Message 2 of 44 in “coverity: fix leaks and error paths”
  1. 00/13 coverity: fix leaks and error pathsJohannes Schindelin via GitGitGadget, Jul 1, 2026
  2. 01/13 load_one_loose_object_map(): fix resource leakJohannes Schindelin via GitGitGadget, Jul 1, 2026
  3. Patrick SteinhardtJul 1, 2026
  4. Junio C HamanoJul 1, 2026
  5. Johannes SchindelinJul 4, 2026
  6. 02/13 loose: avoid closing invalid fd on error pathJohannes Schindelin via GitGitGadget, Jul 1, 2026
  7. Patrick SteinhardtJul 1, 2026
  8. 03/13 download_https_uri_to_file(): do not leak fd upon failureJohannes Schindelin via GitGitGadget, Jul 1, 2026
  9. 04/13 run-command: avoid close(-1) in start_command() error pathsJohannes Schindelin via GitGitGadget, Jul 1, 2026
  10. Patrick SteinhardtJul 1, 2026
  11. 05/13 run_diff_files: avoid memory leakJohannes Schindelin via GitGitGadget, Jul 1, 2026
  12. Patrick SteinhardtJul 1, 2026
  13. Johannes SchindelinJul 4, 2026
  14. 06/13 line-log: avoid redundant copy that leaks in process_rangesJohannes Schindelin via GitGitGadget, Jul 1, 2026
  15. Jeff KingJul 1, 2026
  16. 07/13 dir: free allocations on parse-error paths in read_one_dir()Johannes Schindelin via GitGitGadget, Jul 1, 2026
  17. Patrick SteinhardtJul 1, 2026
  18. Johannes SchindelinJul 4, 2026
  19. 08/13 submodule: fix cwd leak in get_superproject_working_tree()Johannes Schindelin via GitGitGadget, Jul 1, 2026
  20. Patrick SteinhardtJul 1, 2026
  21. Johannes SchindelinJul 4, 2026
  22. 09/13 worktree: fix resource leaks when branch creation failsJohannes Schindelin via GitGitGadget, Jul 1, 2026
  23. 10/13 imap-send: avoid leaking the IMAP upload bufferJohannes Schindelin via GitGitGadget, Jul 1, 2026
  24. 11/13 reftable/table: release filter on error pathJohannes Schindelin via GitGitGadget, Jul 1, 2026
  25. 12/13 fsmonitor: plug token-data leak on early daemon-startup failuresJohannes Schindelin via GitGitGadget, Jul 1, 2026
  26. 13/13 mingw: make exit_process() own the process handle on all pathsJohannes Schindelin via GitGitGadget, Jul 1, 2026
  27. Junio C HamanoJul 1, 2026
  28. 00/12 coverity: fix leaks and error pathsJohannes Schindelin via GitGitGadget, Jul 5, 2026
  29. 01/12 load_one_loose_object_map(): fix resource leakJohannes Schindelin via GitGitGadget, Jul 5, 2026
  30. Patrick SteinhardtJul 7, 2026
  31. 02/12 loose: avoid closing invalid fd on error pathJohannes Schindelin via GitGitGadget, Jul 5, 2026
  32. 03/12 download_https_uri_to_file(): do not leak fd upon failureJohannes Schindelin via GitGitGadget, Jul 5, 2026
  33. 04/12 run-command: avoid `close(-1)` in `start_command()` error pathsJohannes Schindelin via GitGitGadget, Jul 5, 2026
  34. 05/12 line-log: avoid redundant copy that leaks in process_rangesJohannes Schindelin via GitGitGadget, Jul 5, 2026
  35. 06/12 dir: free allocations on parse-error paths in `read_one_dir()`Johannes Schindelin via GitGitGadget, Jul 5, 2026
  36. 07/12 submodule: fix cwd leak in `get_superproject_working_tree()`Johannes Schindelin via GitGitGadget, Jul 5, 2026
  37. Patrick SteinhardtJul 7, 2026
  38. 08/12 worktree: fix resource leaks when branch creation failsJohannes Schindelin via GitGitGadget, Jul 5, 2026
  39. 09/12 imap-send: avoid leaking the IMAP upload bufferJohannes Schindelin via GitGitGadget, Jul 5, 2026
  40. 10/12 reftable/table: release filter on error pathJohannes Schindelin via GitGitGadget, Jul 5, 2026
  41. 11/12 fsmonitor: plug token-data leak on early daemon-startup failuresJohannes Schindelin via GitGitGadget, Jul 5, 2026
  42. 12/12 mingw: make `exit_process()` own the process handle on all pathsJohannes Schindelin via GitGitGadget, Jul 5, 2026
  43. Patrick SteinhardtJul 7, 2026
  44. Junio C HamanoJul 7, 2026

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.