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

[PATCH 05/22] upload-pack: fix leaking child process data on reachability checks

From
Patrick Steinhardt <ps@pks.im>
Date
Aug 26, 2024, 07:21 UTC
Message-ID
<77023421e189aee6837cea9b25841ea258bc06e3.1724656120.git.ps@pks.im>
In-Reply-To
<cover.1724656120.git.ps@pks.im>

We spawn a git-rev-list(1) command to perform reachability checks in "upload-pack.c". We do not release memory associated with the process in error cases though, thus leaking memory.

Fix these by calling `child_process_clear()`.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 t/t5516-fetch-push.sh |  1 +
 upload-pack.c         | 22 ++++++++++++++++------
 2 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 9d693eb57f7..331778bd42c 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -19,6 +19,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
 TEST_CREATE_REPO_NO_TEMPLATE=1
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 D=$(pwd)
diff --git a/upload-pack.c b/upload-pack.c
index f03ba3e98be..c84c3c3b1f5 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -709,10 +709,13 @@ static int get_reachable_list(struct upload_pack_data *data,
 	struct object *o;
 	char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
 	const unsigned hexsz = the_hash_algo->hexsz;
+	int ret;
 
 	if (do_reachable_revlist(&cmd, &data->shallows, reachable,
-				 data->allow_uor) < 0)
-		return -1;
+				 data->allow_uor) < 0) {
+		ret = -1;
+		goto out;
+	}
 
 	while ((i = read_in_full(cmd.out, namebuf, hexsz + 1)) == hexsz + 1) {
 		struct object_id oid;
@@ -736,10 +739,16 @@ static int get_reachable_list(struct upload_pack_data *data,
 	}
 	close(cmd.out);
 
-	if (finish_command(&cmd))
-		return -1;
+	if (finish_command(&cmd)) {
+		ret = -1;
+		goto out;
+	}
 
-	return 0;
+	ret = 0;
+
+out:
+	child_process_clear(&cmd);
+	return ret;
 }
 
 static int has_unreachable(struct object_array *src, enum allow_uor allow_uor)
@@ -749,7 +758,7 @@ static int has_unreachable(struct object_array *src, enum allow_uor allow_uor)
 	int i;
 
 	if (do_reachable_revlist(&cmd, src, NULL, allow_uor) < 0)
-		return 1;
+		goto error;
 
 	/*
 	 * The commits out of the rev-list are not ancestors of
@@ -775,6 +784,7 @@ static int has_unreachable(struct object_array *src, enum allow_uor allow_uor)
 error:
 	if (cmd.out >= 0)
 		close(cmd.out);
+	child_process_clear(&cmd);
 	return 1;
 }
 
-- 
2.46.0.164.g477ce5ccd6.dirty
Previous: Patrick SteinhardtNext: Junio C Hamano
Message 11 of 70 in “Memory leak fixes (pt.6)”
  1. 00/22 Memory leak fixes (pt.6)Patrick Steinhardt, Aug 26, 2024
  2. 01/22 t/test-lib: allow skipping leak checks for passing testsPatrick Steinhardt, Aug 26, 2024
  3. Junio C HamanoAug 27, 2024
  4. Toon claesAug 29, 2024
  5. Patrick SteinhardtAug 30, 2024
  6. 02/22 fetch-pack: fix memory leaks on fetch negotiationPatrick Steinhardt, Aug 26, 2024
  7. 03/22 send-pack: fix leaking common object IDsPatrick Steinhardt, Aug 26, 2024
  8. 04/22 builtin/push: fix leaking refspec query resultPatrick Steinhardt, Aug 26, 2024
  9. Junio C HamanoAug 30, 2024
  10. Patrick SteinhardtSep 2, 2024
  11. 05/22 upload-pack: fix leaking child process data on reachability checksPatrick Steinhardt, Aug 26, 2024
  12. Junio C HamanoAug 30, 2024
  13. 06/22 submodule: fix leaking fetch task dataPatrick Steinhardt, Aug 26, 2024
  14. 07/22 builtin/submodule--helper: fix leaking refs on push-checkPatrick Steinhardt, Aug 26, 2024
  15. 08/22 remote: fix leaking tracking refsPatrick Steinhardt, Aug 26, 2024
  16. Junio C HamanoSep 4, 2024
  17. 09/22 remote: fix leak in reachability check of a remote-tracking refPatrick Steinhardt, Aug 26, 2024
  18. 10/22 send-pack: fix leaking push cert noncePatrick Steinhardt, Aug 26, 2024
  19. Junio C HamanoSep 4, 2024
  20. 11/22 gpg-interface: fix misdesigned signing key interfacesPatrick Steinhardt, Aug 26, 2024
  21. Junio C HamanoSep 4, 2024
  22. 12/22 object: clear grafts when clearing parsed object poolPatrick Steinhardt, Aug 26, 2024
  23. 13/22 shallow: free grafts when unregistering themPatrick Steinhardt, Aug 26, 2024
  24. 14/22 shallow: fix leaking members of `struct shallow_info`Patrick Steinhardt, Aug 26, 2024
  25. Toon claesAug 29, 2024
  26. Junio C HamanoAug 29, 2024
  27. Patrick SteinhardtAug 30, 2024
  28. 15/22 negotiator/skipping: fix leaking commit entriesPatrick Steinhardt, Aug 26, 2024
  29. Calvin WanAug 28, 2024
  30. Josh SteadmonAug 28, 2024
  31. Patrick SteinhardtAug 29, 2024
  32. Calvin WanAug 29, 2024
  33. 16/22 builtin/repack: fix leaking line buffer when packing promisorsPatrick Steinhardt, Aug 26, 2024
  34. Junio C HamanoSep 4, 2024
  35. 17/22 builtin/pack-objects: plug leaking list of keep-packsPatrick Steinhardt, Aug 26, 2024
  36. 18/22 builtin/grep: fix leaking object contextPatrick Steinhardt, Aug 26, 2024
  37. Junio C HamanoSep 4, 2024
  38. 19/22 builtin/fmt-merge-msg: fix leaking buffersPatrick Steinhardt, Aug 26, 2024
  39. 20/22 match-trees: fix leaking prefixes in `shift_tree()`Patrick Steinhardt, Aug 26, 2024
  40. Junio C HamanoSep 4, 2024
  41. 21/22 merge-ort: fix two leaks when handling directory rename modificationsPatrick Steinhardt, Aug 26, 2024
  42. Junio C HamanoSep 4, 2024
  43. Elijah NewrenSep 5, 2024
  44. 22/22 builtin/repack: fix leaking keep-pack listPatrick Steinhardt, Aug 26, 2024
  45. Junio C HamanoSep 4, 2024
  46. 00/22 Memory leak fixes (pt.6)Patrick Steinhardt, Sep 5, 2024
  47. 01/22 t/test-lib: allow skipping leak checks for passing testsPatrick Steinhardt, Sep 5, 2024
  48. 02/22 fetch-pack: fix memory leaks on fetch negotiationPatrick Steinhardt, Sep 5, 2024
  49. 03/22 send-pack: fix leaking common object IDsPatrick Steinhardt, Sep 5, 2024
  50. 04/22 builtin/push: fix leaking refspec query resultPatrick Steinhardt, Sep 5, 2024
  51. 05/22 upload-pack: fix leaking child process data on reachability checksPatrick Steinhardt, Sep 5, 2024
  52. 06/22 submodule: fix leaking fetch task dataPatrick Steinhardt, Sep 5, 2024
  53. 07/22 builtin/submodule--helper: fix leaking refs on push-checkPatrick Steinhardt, Sep 5, 2024
  54. 08/22 remote: fix leaking tracking refsPatrick Steinhardt, Sep 5, 2024
  55. 09/22 remote: fix leak in reachability check of a remote-tracking refPatrick Steinhardt, Sep 5, 2024
  56. 10/22 send-pack: fix leaking push cert noncePatrick Steinhardt, Sep 5, 2024
  57. 11/22 gpg-interface: fix misdesigned signing key interfacesPatrick Steinhardt, Sep 5, 2024
  58. 12/22 object: clear grafts when clearing parsed object poolPatrick Steinhardt, Sep 5, 2024
  59. 13/22 shallow: free grafts when unregistering themPatrick Steinhardt, Sep 5, 2024
  60. 14/22 shallow: fix leaking members of `struct shallow_info`Patrick Steinhardt, Sep 5, 2024
  61. 15/22 negotiator/skipping: fix leaking commit entriesPatrick Steinhardt, Sep 5, 2024
  62. 16/22 builtin/repack: fix leaking line buffer when packing promisorsPatrick Steinhardt, Sep 5, 2024
  63. 17/22 builtin/pack-objects: plug leaking list of keep-packsPatrick Steinhardt, Sep 5, 2024
  64. 18/22 builtin/grep: fix leaking object contextPatrick Steinhardt, Sep 5, 2024
  65. 19/22 builtin/fmt-merge-msg: fix leaking buffersPatrick Steinhardt, Sep 5, 2024
  66. 20/22 match-trees: fix leaking prefixes in `shift_tree()`Patrick Steinhardt, Sep 5, 2024
  67. 21/22 merge-ort: fix two leaks when handling directory rename modificationsPatrick Steinhardt, Sep 5, 2024
  68. 22/22 builtin/repack: fix leaking keep-pack listPatrick Steinhardt, Sep 5, 2024
  69. Junio C HamanoSep 8, 2024
  70. Junio C HamanoSep 12, 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.