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

[PATCH] repack: free existing_cruft array after use

From
Jeff King <peff@peff.net>
Date
Oct 7, 2023, 17:20 UTC
Message-ID
<20231007172031.GA1524950@coredump.intra.peff.net>
In-Reply-To
<e7beb2060dad648ec5c3fa8984e432ee243ae012.1696293862.git.me@ttaylorr.com>
On Mon, Oct 02, 2023 at 08:44:32PM -0400, Taylor Blau wrote:
Show 9 quoted lines
> +static void collapse_small_cruft_packs(FILE *in, size_t max_size,
> +				       struct existing_packs *existing)
> +{
> +	struct packed_git **existing_cruft, *p;
> +	struct strbuf buf = STRBUF_INIT;
> [...]
> +
> +	strbuf_release(&buf);
> +}

Coverity (using the just-merged-to-next version of the workflow file!) flagged a leak here. Since the topic (tb/repack-max-cruft-size) is in 'next', I think we'd want this on top:

-- >8 --
Subject: [PATCH] repack: free existing_cruft array after use

We allocate an array of packed_git pointers so that we can sort the list of cruft packs, but we never free the array, causing a small leak. Note that we don't need to free the packed_git structs themselves; they're owned by the repository object.

Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/repack.c | 1 +
 1 file changed, 1 insertion(+)
diff --git a/builtin/repack.c b/builtin/repack.c
index a1a893d952..69e8f302c0 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -955,6 +955,7 @@ static void collapse_small_cruft_packs(FILE *in, size_t max_size,
 			existing->non_kept_packs.items[i].string);
 
 	strbuf_release(&buf);
+	free(existing_cruft);
 }
 
 static int write_cruft_pack(const struct pack_objects_args *args,
-- 
2.42.0.884.gc318dcfe19
Previous: Junio C HamanoNext: Taylor Blau
Message 19 of 21 in “repack: implement `--cruft-max-size`”
  1. 0/2 repack: implement `--cruft-max-size`Taylor Blau, Sep 7, 2023
  2. 1/2 t7700: split cruft-related tests to t7704Taylor Blau, Sep 7, 2023
  3. Eric SunshineSep 8, 2023
  4. 2/2 builtin/repack.c: implement support for `--cruft-max-size`Taylor Blau, Sep 7, 2023
  5. Junio C HamanoSep 7, 2023
  6. Taylor BlauSep 25, 2023
  7. Patrick SteinhardtSep 8, 2023
  8. Taylor BlauOct 2, 2023
  9. 0/3 repack: implement `--cruft-max-size`Taylor Blau, Oct 3, 2023
  10. 1/3 t7700: split cruft-related tests to t7704Taylor Blau, Oct 3, 2023
  11. 2/3 builtin/repack.c: parse `--max-pack-size` with OPT_MAGNITUDETaylor Blau, Oct 3, 2023
  12. Patrick SteinhardtOct 5, 2023
  13. Taylor BlauOct 5, 2023
  14. Junio C HamanoOct 5, 2023
  15. 3/3 builtin/repack.c: implement support for `--max-cruft-size`Taylor Blau, Oct 3, 2023
  16. Patrick SteinhardtOct 5, 2023
  17. Taylor BlauOct 5, 2023
  18. Junio C HamanoOct 5, 2023
  19. repack: free existing_cruft array after useJeff King, Oct 7, 2023
  20. Taylor BlauOct 9, 2023
  21. Junio C HamanoOct 9, 2023

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.