]> Kevux Git Server - rit/commit
pack-bitmap: fix memory leak if load_bitmap() failed
authorTaylor Blau <me@ttaylorr.com>
Tue, 1 Jul 2025 05:32:07 +0000 (05:32 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 1 Jul 2025 21:41:53 +0000 (14:41 -0700)
commit3367b6657c456788e37c335bdd3225e517d2c804
tree3942137e7c46e15a853bfaa5243932f827fd4503
parentb32feae0f1b21faaf8e191e8d3314a32470a536b
pack-bitmap: fix memory leak if load_bitmap() failed

After going through the "failed" label, load_bitmap() will return -1,
and its caller (either prepare_bitmap_walk() or prepare_bitmap_git())
will then call free_bitmap_index().

That function would have done:

    struct stored_bitmap *sb;
    kh_foreach_value(b->bitmaps, sb {
      ewah_pool_free(sb->root);
      free(sb);
    });

, but won't since load_bitmap() already called kh_destroy_oid_map() and
NULL'd the "bitmaps" pointer from within its "failed" label. Thus if you
got part of the way through loading bitmap entries and then failed, you
would leak all of the previous entries that you were able to load
successfully.

The solution is to remove the error handling code in load_bitmap(), because
its caller will always call free_bitmap_index() in case of an error.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Lidong Yan <502024330056@smail.nju.edu.cn>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pack-bitmap.c