Skip to content

Commit

Permalink
builtin/check-ignore: clear_pathspec before returning
Browse files Browse the repository at this point in the history
parse_pathspec() allocates new memory into pathspec, therefore we need
to free it when we're done.

An UNLEAK would probably be just as good here - but clear_pathspec() is
not much more work so we might as well use it. check_ignore() is either
called once directly from cmd_check_ignore() (in which case the leak
really doesnt matter), or it can be called multiple times in a loop from
check_ignore_stdin_paths(), in which case we're potentially leaking
multiple times - but even in this scenario the leak is so small as to
have no real consequence.

Found while running t0008:

Direct leak of 112 byte(s) in 1 object(s) allocated from:
    #0 0x49a85d in malloc ../projects/compiler-rt/lib/asan/asan_malloc_linux.cpp:145:3
    #1 0x9aca44 in do_xmalloc wrapper.c:41:8
    git-l10n#2 0x9aca1a in xmalloc wrapper.c:62:9
    git-l10n#3 0x873c17 in parse_pathspec pathspec.c:582:2
    git-l10n#4 0x503eb8 in check_ignore builtin/check-ignore.c:90:2
    git-l10n#5 0x5038af in cmd_check_ignore builtin/check-ignore.c:190:17
    git-l10n#6 0x4cd91d in run_builtin git.c:467:11
    git-l10n#7 0x4cb5f3 in handle_builtin git.c:719:3
    git-l10n#8 0x4ccf47 in run_argv git.c:808:4
    git-l10n#9 0x4caf49 in cmd_main git.c:939:19
    git-l10n#10 0x69e43e in main common-main.c:52:11
    git-l10n#11 0x7f18bb0dd349 in __libc_start_main (/lib64/libc.so.6+0x24349)

Indirect leak of 65 byte(s) in 1 object(s) allocated from:
    #0 0x49ab79 in realloc ../projects/compiler-rt/lib/asan/asan_malloc_linux.cpp:164:3
    #1 0x9acc46 in xrealloc wrapper.c:126:8
    git-l10n#2 0x93baed in strbuf_grow strbuf.c:98:2
    git-l10n#3 0x93d696 in strbuf_vaddf strbuf.c:392:3
    git-l10n#4 0x9400c6 in xstrvfmt strbuf.c:979:2
    git-l10n#5 0x940253 in xstrfmt strbuf.c:989:8
    git-l10n#6 0x92b72a in prefix_path_gently setup.c:115:15
    git-l10n#7 0x87442d in init_pathspec_item pathspec.c:439:11
    git-l10n#8 0x873cef in parse_pathspec pathspec.c:589:3
    git-l10n#9 0x503eb8 in check_ignore builtin/check-ignore.c:90:2
    git-l10n#10 0x5038af in cmd_check_ignore builtin/check-ignore.c:190:17
    git-l10n#11 0x4cd91d in run_builtin git.c:467:11
    git-l10n#12 0x4cb5f3 in handle_builtin git.c:719:3
    git-l10n#13 0x4ccf47 in run_argv git.c:808:4
    git-l10n#14 0x4caf49 in cmd_main git.c:939:19
    git-l10n#15 0x69e43e in main common-main.c:52:11
    git-l10n#16 0x7f18bb0dd349 in __libc_start_main (/lib64/libc.so.6+0x24349)

Indirect leak of 2 byte(s) in 1 object(s) allocated from:
    #0 0x486834 in strdup ../projects/compiler-rt/lib/asan/asan_interceptors.cpp:452:3
    #1 0x9ac9e8 in xstrdup wrapper.c:29:14
    git-l10n#2 0x874542 in init_pathspec_item pathspec.c:468:20
    git-l10n#3 0x873cef in parse_pathspec pathspec.c:589:3
    git-l10n#4 0x503eb8 in check_ignore builtin/check-ignore.c:90:2
    git-l10n#5 0x5038af in cmd_check_ignore builtin/check-ignore.c:190:17
    git-l10n#6 0x4cd91d in run_builtin git.c:467:11
    git-l10n#7 0x4cb5f3 in handle_builtin git.c:719:3
    git-l10n#8 0x4ccf47 in run_argv git.c:808:4
    git-l10n#9 0x4caf49 in cmd_main git.c:939:19
    git-l10n#10 0x69e43e in main common-main.c:52:11
    git-l10n#11 0x7f18bb0dd349 in __libc_start_main (/lib64/libc.so.6+0x24349)

SUMMARY: AddressSanitizer: 179 byte(s) leaked in 3 allocation(s).

Signed-off-by: Andrzej Hunt <ajrhunt@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
ahunt authored and gitster committed Apr 28, 2021
1 parent 4fa2687 commit 2656443
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions builtin/check-ignore.c
Expand Up @@ -118,6 +118,7 @@ static int check_ignore(struct dir_struct *dir,
num_ignored++;
}
free(seen);
clear_pathspec(&pathspec);

return num_ignored;
}
Expand Down

0 comments on commit 2656443

Please sign in to comment.