Skip to content

Commit f2bcc69

Browse files
avargitster
authored andcommitted
index-pack: fix memory leaks
Fix various memory leaks in "git index-pack", due to how tightly coupled this command is with the revision walking this doesn't make any new tests pass. But e.g. this now passes, and had several failures before, i.e. we still have failures in tests 3, 5 etc., which are being skipped here. ./t5300-pack-object.sh --run=1-2,4,6-27,30-42 It is a bit odd that we'll free "opts.anomaly", since the "opts" is a "struct pack_idx_option" declared in pack.h. In pack-write.c there's a reset_pack_idx_option(), but it only wipes the contents, but doesn't free() anything. Doing this here in cmd_index_pack() is correct because while the struct is declared in pack.h, this code in builtin/index-pack.c (in read_v2_anomalous_offsets()) is what allocates the "opts.anomaly", so we should also free it here. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 715d08a commit f2bcc69

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

builtin/index-pack.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,7 @@ static void *threaded_second_pass(void *data)
11091109
list_add(&child->list, &work_head);
11101110
base_cache_used += child->size;
11111111
prune_base_data(NULL);
1112+
free_base_data(child);
11121113
} else {
11131114
/*
11141115
* This child does not have its own children. It may be
@@ -1131,6 +1132,7 @@ static void *threaded_second_pass(void *data)
11311132

11321133
p = next_p;
11331134
}
1135+
FREE_AND_NULL(child);
11341136
}
11351137
work_unlock();
11361138
}
@@ -1424,6 +1426,7 @@ static void fix_unresolved_deltas(struct hashfile *f)
14241426
* object).
14251427
*/
14261428
append_obj_to_pack(f, d->oid.hash, data, size, type);
1429+
free(data);
14271430
threaded_second_pass(NULL);
14281431

14291432
display_progress(progress, nr_resolved_deltas);
@@ -1703,6 +1706,7 @@ static void show_pack_info(int stat_only)
17031706
i + 1,
17041707
chain_histogram[i]);
17051708
}
1709+
free(chain_histogram);
17061710
}
17071711

17081712
int cmd_index_pack(int argc, const char **argv, const char *prefix)
@@ -1932,6 +1936,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
19321936
if (do_fsck_object && fsck_finish(&fsck_options))
19331937
die(_("fsck error in pack objects"));
19341938

1939+
free(opts.anomaly);
19351940
free(objects);
19361941
strbuf_release(&index_name_buf);
19371942
strbuf_release(&rev_index_name_buf);

0 commit comments

Comments
 (0)