summaryrefslogtreecommitdiff
path: root/builtin/help.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-11-26 10:21:58 +0900
committerJunio C Hamano <gitster@pobox.com>2024-11-26 10:21:58 +0900
commitc6c977e82b94a8266a1f24bed6fcddb15bd01d1c (patch)
tree665797668fb1bd2ac1bc0c3a70397d30251f1c01 /builtin/help.c
parent6ea2d9d271a56afa0e77cd45796ea0592aa9c2d4 (diff)
parentfc1ddf42af6742fae7e770cae20e30d7902014c0 (diff)
Merge branch 'ps/leakfixes-part-10' into ps/bisect-double-free-fix
* ps/leakfixes-part-10: (27 commits) t: remove TEST_PASSES_SANITIZE_LEAK annotations test-lib: unconditionally enable leak checking t: remove unneeded !SANITIZE_LEAK prerequisites t: mark some tests as leak free t5601: work around leak sanitizer issue git-compat-util: drop now-unused `UNLEAK()` macro global: drop `UNLEAK()` annotation t/helper: fix leaking commit graph in "read-graph" subcommand builtin/branch: fix leaking sorting options builtin/init-db: fix leaking directory paths builtin/help: fix leaks in `check_git_cmd()` help: fix leaking return value from `help_unknown_cmd()` help: fix leaking `struct cmdnames` help: refactor to not use globals for reading config builtin/sparse-checkout: fix leaking sanitized patterns split-index: fix memory leak in `move_cache_to_base_index()` git: refactor builtin handling to use a `struct strvec` git: refactor alias handling to use a `struct strvec` strvec: introduce new `strvec_splice()` function line-log: fix leak when rewriting commit parents ...
Diffstat (limited to 'builtin/help.c')
-rw-r--r--builtin/help.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/builtin/help.c b/builtin/help.c
index 4a5a079070..6a72d991a8 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -551,12 +551,12 @@ static void show_html_page(const char *page)
open_html(page_path.buf);
}
-static const char *check_git_cmd(const char* cmd)
+static char *check_git_cmd(const char *cmd)
{
char *alias;
if (is_git_command(cmd))
- return cmd;
+ return xstrdup(cmd);
alias = alias_lookup(cmd);
if (alias) {
@@ -589,14 +589,13 @@ static const char *check_git_cmd(const char* cmd)
die(_("bad alias.%s string: %s"), cmd,
split_cmdline_strerror(count));
free(argv);
- UNLEAK(alias);
return alias;
}
if (exclude_guides)
return help_unknown_cmd(cmd);
- return cmd;
+ return xstrdup(cmd);
}
static void no_help_format(const char *opt_mode, enum help_format fmt)
@@ -642,6 +641,7 @@ int cmd_help(int argc,
{
int nongit;
enum help_format parsed_help_format;
+ char *command = NULL;
const char *page;
argc = parse_options(argc, argv, prefix, builtin_help_options,
@@ -713,9 +713,9 @@ int cmd_help(int argc,
if (help_format == HELP_FORMAT_NONE)
help_format = parse_help_format(DEFAULT_HELP_FORMAT);
- argv[0] = check_git_cmd(argv[0]);
+ command = check_git_cmd(argv[0]);
- page = cmd_to_page(argv[0]);
+ page = cmd_to_page(command);
switch (help_format) {
case HELP_FORMAT_NONE:
case HELP_FORMAT_MAN:
@@ -729,5 +729,6 @@ int cmd_help(int argc,
break;
}
+ free(command);
return 0;
}