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

Re: [PATCH] pack-redundant: fix memory leak when open_pack_index() fails

From
Patrick Steinhardt <ps@pks.im>
Date
Feb 24, 2026, 10:14 UTC
Message-ID
<aZ16EWgLFbTPwM-v@pks.im>
In-Reply-To
<20260221103900.41740-1-sahityajb@gmail.com>
On Sat, Feb 21, 2026 at 04:08:59PM +0530, Sahitya Chandra wrote:
> diff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c
> index e4ecf774ca..86749bb7e7 100644
> --- a/builtin/pack-redundant.c
> +++ b/builtin/pack-redundant.c

It's arguably not really worth it to work on git-pack-redundant(1) as it's deprecated and dies unless you pass "--i-still-use-this". But the fix is small enough, so it doesn't hurt much, either.

Show 9 quoted lines
> @@ -546,8 +546,10 @@ static struct pack_list * add_pack(struct packed_git *p)
>  	l.pack = p;
>  	llist_init(&l.remaining_objects);
>  
> -	if (open_pack_index(p))
> +	if (open_pack_index(p)) {
> +		llist_free(l.remaining_objects);
>  		return NULL;
> +	}

Right. The confusing part here is that `llist_init()` doesn't only initialize the data structure as its name might suggest, but it also ends up allocating memory. It would be great do adjust this interface to clarify, but that is certainly out of scope for this patch series.

By the way, can't we avoid the memory allocation altogether by reordering the code so that we try to open the pack before we allocate memory?

Thanks!
Patrick
Previous: Sahitya Chandra
Message 2 of 2 in “pack-redundant: fix memory leak when open_pack_index() fails”
  1. pack-redundant: fix memory leak when open_pack_index() failsSahitya Chandra, Feb 21, 2026
  2. Patrick SteinhardtFeb 24, 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.