From: Sahitya Chandra <sahityajb@gmail.com>
To: git@vger.kernel.org
Cc: Sahitya Chandra <sahityajb@gmail.com>,
Junio C Hamano <gitster@pobox.com>
Subject: [PATCH] pack-redundant: fix memory leak when open_pack_index() fails
Date: Sat, 21 Feb 2026 16:08:59 +0530 [thread overview]
Message-ID: <20260221103900.41740-1-sahityajb@gmail.com> (raw)
In add_pack(), we allocate l.remaining_objects with llist_init() before
calling open_pack_index(). If open_pack_index() fails we return NULL
without freeing the allocated list, leaking the memory.
Fix by calling llist_free(l.remaining_objects) on the error path before
returning.
Signed-off-by: Sahitya Chandra <sahityajb@gmail.com>
---
builtin/pack-redundant.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
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
@@ -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;
+ }
base = p->index_data;
base += 256 * 4 + ((p->index_version < 2) ? 4 : 8);
--
2.43.0
next reply other threads:[~2026-02-21 10:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-21 10:38 Sahitya Chandra [this message]
2026-02-24 10:14 ` [PATCH] pack-redundant: fix memory leak when open_pack_index() fails Patrick Steinhardt
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=20260221103900.41740-1-sahityajb@gmail.com \
--to=sahityajb@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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