Skip to content

Commit 6cdb67b

Browse files
ttaylorrgitster
authored andcommitted
pack-bitmap-write: deep-clear the bb_commit slab
The `bb_commit` commit slab is used by the pack-bitmap-write machinery to track various pieces of bookkeeping used to generate reachability bitmaps. Even though we clear the slab when freeing the bitmap_builder struct (with `bitmap_builder_clear()`), there are still pointers which point to locations in memory that have not yet been freed, resulting in a leak. Plug the leak by introducing a suitable `free_fn` for the `struct bb_commit` type, and make sure it is called on each member of the slab via the `deep_clear_bb_data()` function. Note that it is possible for both of the arguments to `bitmap_free()` to be NULL, but `bitmap_free()` is a noop for NULL arguments, so it is OK to pass them unconditionally. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 66f0c71 commit 6cdb67b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pack-bitmap-write.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,13 @@ struct bb_commit {
198198
unsigned idx; /* within selected array */
199199
};
200200

201+
static void clear_bb_commit(struct bb_commit *commit)
202+
{
203+
free_commit_list(commit->reverse_edges);
204+
bitmap_free(commit->commit_mask);
205+
bitmap_free(commit->bitmap);
206+
}
207+
201208
define_commit_slab(bb_data, struct bb_commit);
202209

203210
struct bitmap_builder {
@@ -339,7 +346,7 @@ static void bitmap_builder_init(struct bitmap_builder *bb,
339346

340347
static void bitmap_builder_clear(struct bitmap_builder *bb)
341348
{
342-
clear_bb_data(&bb->data);
349+
deep_clear_bb_data(&bb->data, clear_bb_commit);
343350
free(bb->commits);
344351
bb->commits_nr = bb->commits_alloc = 0;
345352
}

0 commit comments

Comments
 (0)