]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pack-redundant: fix memory leak when open_pack_index() fails
authorSahitya Chandra <sahityajb@gmail.com>
Sat, 21 Feb 2026 10:38:59 +0000 (16:08 +0530)
committerJunio C Hamano <gitster@pobox.com>
Sun, 22 Feb 2026 05:26:53 +0000 (21:26 -0800)
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>
builtin/pack-redundant.c

index e4ecf774ca640559950bc9f55a91db962fe2596b..86749bb7e77ae7fa8abef7cd42a6859c3608f491 100644 (file)
@@ -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);