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

[PATCH] bundle-uri: plug leak in unbundle_from_file()

From
Toon Claes <toon@iotcl.com>
Date
Aug 26, 2024, 08:30 UTC
Message-ID
<20240826083052.1542228-1-toon@iotcl.com>

When the function returns early, the variable bundle_ref is not released through strbuf_release().

Fix this leak. And while at it, remove assignments in the conditions of the "if" statements as suggested in the CodingGuidelines.

Signed-off-by: Toon Claes <toon@iotcl.com>
---
 bundle-uri.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/bundle-uri.c b/bundle-uri.c
index 1e0ee156ba..eb49cba182 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -367,17 +367,21 @@ static int unbundle_from_file(struct repository *r, const char *file)
 	struct strbuf bundle_ref = STRBUF_INIT;
 	size_t bundle_prefix_len;

-	if ((bundle_fd = read_bundle_header(file, &header)) < 0)
-		return 1;
+	bundle_fd = read_bundle_header(file, &header);
+	if (bundle_fd < 0) {
+		result = 1;
+		goto cleanup;
+	}

 	/*
 	 * Skip the reachability walk here, since we will be adding
 	 * a reachable ref pointing to the new tips, which will reach
 	 * the prerequisite commits.
 	 */
-	if ((result = unbundle(r, &header, bundle_fd, NULL,
-			       VERIFY_BUNDLE_QUIET | (fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0))))
-		return 1;
+	result = unbundle(r, &header, bundle_fd, NULL,
+			  VERIFY_BUNDLE_QUIET | (fetch_pack_fsck_objects() ? VERIFY_BUNDLE_FSCK : 0));
+	if (result)
+		goto cleanup;

 	/*
 	 * Convert all refs/heads/ from the bundle into refs/bundles/
@@ -406,6 +410,8 @@ static int unbundle_from_file(struct repository *r, const char *file)
 				0, UPDATE_REFS_MSG_ON_ERR);
 	}

+cleanup:
+	strbuf_release(&bundle_ref);
 	bundle_header_release(&header);
 	return result;
 }
--
2.46.0
Next: Patrick Steinhardt
Message 1 of 9 in “bundle-uri: plug leak in unbundle_from_file()”
  1. bundle-uri: plug leak in unbundle_from_file()Toon Claes, Aug 26, 2024
  2. Patrick SteinhardtAug 26, 2024
  3. Junio C HamanoAug 26, 2024
  4. Toon ClaesOct 1, 2024
  5. Junio C HamanoOct 1, 2024
  6. Toon ClaesOct 10, 2024
  7. bundle-uri: plug leak in unbundle_from_file()Toon Claes, Oct 10, 2024
  8. Patrick SteinhardtOct 10, 2024
  9. Junio C HamanoOct 10, 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.