public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Sahitya Chandra <sahityajb@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] pack-redundant: fix memory leak when open_pack_index() fails
Date: Tue, 24 Feb 2026 11:14:41 +0100	[thread overview]
Message-ID: <aZ16EWgLFbTPwM-v@pks.im> (raw)
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.

> @@ -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

      reply	other threads:[~2026-02-24 10:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-21 10:38 [PATCH] pack-redundant: fix memory leak when open_pack_index() fails Sahitya Chandra
2026-02-24 10:14 ` Patrick Steinhardt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aZ16EWgLFbTPwM-v@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=sahityajb@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox