summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorAndrzej Hunt <ajrhunt@google.com>2021-04-25 14:16:10 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-04-28 00:25:44 (GMT)
commit4c217a4c34be29aee4aac402eed668438e8d21a4 (patch)
tree0c071d84093c0999a99322fc4ee18b72911e4766 /builtin
parent5493ce7af95a266f4207d85b53fe59a8a1fa2d24 (diff)
downloadgit-4c217a4c34be29aee4aac402eed668438e8d21a4.zip
git-4c217a4c34be29aee4aac402eed668438e8d21a4.tar.gz
git-4c217a4c34be29aee4aac402eed668438e8d21a4.tar.bz2
ls-files: free max_prefix when done
common_prefix() returns a new string, which we store in max_prefix - this string needs to be freed to avoid a leak. This leak is happening in cmd_ls_files, hence is of no real consequence - an UNLEAK would be just as good, but we might as well free the string properly. Leak found while running t0002, see output below: Direct leak of 8 byte(s) in 1 object(s) allocated from: #0 0x49a85d in malloc /home/abuild/rpmbuild/BUILD/llvm-11.0.0.src/build/../projects/compiler-rt/lib/asan/asan_malloc_linux.cpp:145:3 #1 0x9ab1b4 in do_xmalloc wrapper.c:41:8 #2 0x9ab248 in do_xmallocz wrapper.c:75:8 #3 0x9ab22a in xmallocz wrapper.c:83:9 #4 0x9ab2d7 in xmemdupz wrapper.c:99:16 #5 0x78d6a4 in common_prefix dir.c:191:15 #6 0x5aca48 in cmd_ls_files builtin/ls-files.c:669:16 #7 0x4cd92d in run_builtin git.c:453:11 #8 0x4cb5fa in handle_builtin git.c:704:3 #9 0x4ccf57 in run_argv git.c:771:4 #10 0x4caf49 in cmd_main git.c:902:19 #11 0x69ce2e in main common-main.c:52:11 #12 0x7f64d4d94349 in __libc_start_main (/lib64/libc.so.6+0x24349) Signed-off-by: Andrzej Hunt <ajrhunt@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/ls-files.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index f6f9e48..7d1ac1e 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -530,7 +530,7 @@ static int option_parse_exclude_standard(const struct option *opt,
int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
{
int require_work_tree = 0, show_tag = 0, i;
- const char *max_prefix;
+ char *max_prefix;
struct dir_struct dir;
struct pattern_list *pl;
struct string_list exclude_list = STRING_LIST_INIT_NODUP;
@@ -708,5 +708,6 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
}
dir_clear(&dir);
+ free(max_prefix);
return 0;
}