pack-redundant: fix memory leak when open_pack_index() fails
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Sahitya Chandra committed
Feb 21, 2026 at 16:08 UTC
7451864bfac0fc7ac829aceecd7f339b80dac732
1 file changed
+3
-1
builtin/pack-redundant.c
+3
-1
@@ -546,8 +546,10 @@ static struct pack_list * add_pack(struct packed_git *p)
546
l.pack = p;
547
llist_init(&l.remaining_objects);
548
549
- if (open_pack_index(p))
549
+ if (open_pack_index(p)) {
550
+ llist_free(l.remaining_objects);
551
return NULL;
552
+ }
553
554
base = p->index_data;
555
base += 256 * 4 + ((p->index_version < 2) ? 4 : 8);