Skip to content

Commit

Permalink
read-cache: call diff_setup_done to avoid leak
Browse files Browse the repository at this point in the history
repo_diff_setup() calls through to diff.c's static prep_parse_options(),
which in  turn allocates a new array into diff_opts.parseopts.
diff_setup_done() is responsible for freeing that array, and has the
benefit of verifying diff_opts too - hence we add a call to
diff_setup_done() to avoid leaking parseopts.

Output from the leak as found while running t0090 with LSAN:

Direct leak of 7120 byte(s) in 1 object(s) allocated from:
    #0 0x49a82d in malloc ../projects/compiler-rt/lib/asan/asan_malloc_linux.cpp:145:3
    #1 0xa8bf89 in do_xmalloc wrapper.c:41:8
    #2 0x7a7bae in prep_parse_options diff.c:5636:2
    #3 0x7a7bae in repo_diff_setup diff.c:4611:2
    #4 0x93716c in repo_index_has_changes read-cache.c:2518:3
    #5 0x872233 in unclean merge-ort-wrappers.c:12:14
    #6 0x872233 in merge_ort_recursive merge-ort-wrappers.c:53:6
    #7 0x5d5b11 in try_merge_strategy builtin/merge.c:752:12
    git#8 0x5d0b6b in cmd_merge builtin/merge.c:1666:9
    git#9 0x4ce83e in run_builtin git.c:475:11
    git#10 0x4ccafe in handle_builtin git.c:729:3
    git#11 0x4cb01c in run_argv git.c:818:4
    git#12 0x4cb01c in cmd_main git.c:949:19
    git#13 0x6bdc2d in main common-main.c:52:11
    git#14 0x7f551eb51349 in __libc_start_main (/lib64/libc.so.6+0x24349)

SUMMARY: AddressSanitizer: 7120 byte(s) leaked in 1 allocation(s)

Signed-off-by: Andrzej Hunt <andrzej@ahunt.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
ahunt authored and gitster committed Jul 26, 2021
1 parent d7cf418 commit 8d833e9
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -2499,6 +2499,7 @@ int repo_index_has_changes(struct repository *repo,
opt.flags.exit_with_status = 1;
if (!sb)
opt.flags.quick = 1;
diff_setup_done(&opt);
do_diff_cache(&cmp, &opt);
diffcore_std(&opt);
for (i = 0; sb && i < diff_queued_diff.nr; i++) {
Expand Down

0 comments on commit 8d833e9

Please sign in to comment.