Skip to content

Commit 47cd649

Browse files
author
Rob Sanders
committed
Fix memory leak in cli_get_optarg_comphelp when formatting 'help' entries
1 parent a71ff5e commit 47cd649

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

libcli.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,7 +2841,8 @@ static void cli_get_optarg_comphelp(struct cli_def *cli, struct cli_optarg *opta
28412841
char *allow_buildmode = BUILDMODE_NO;
28422842
int (*get_completions)(struct cli_def *, const char *, const char *, struct cli_comphelp *) = NULL;
28432843
char *tptr = NULL;
2844-
2844+
char *tname = NULL;
2845+
28452846
// If we've already seen a value by this exact name, skip it, unless the multiple flag is set
28462847
if (cli_find_optarg_value(cli, optarg->name, NULL) && !(optarg->flags & (CLI_CMD_OPTION_MULTIPLE))) return;
28472848

@@ -2884,16 +2885,17 @@ static void cli_get_optarg_comphelp(struct cli_def *cli, struct cli_optarg *opta
28842885
}
28852886

28862887
// Fill in with help text or completor value(s) as indicated
2887-
if (lastchar == '?' && asprintf(&tptr, "%s%s%s", delim_start, optarg->name, delim_end) != -1) {
2888+
if (lastchar == '?' && asprintf(&tname, "%s%s%s", delim_start, optarg->name, delim_end) != -1) {
28882889
if (optarg->flags & CLI_CMD_ALLOW_BUILDMODE) allow_buildmode = BUILDMODE_YES;
2889-
if (help_insert && (asprintf(&tptr, " %-20s enter '%s' to %s%s", tptr, optarg->name,
2890+
if (help_insert && (asprintf(&tptr, " %-20s enter '%s' to %s%s", tname, optarg->name,
28902891
(optarg->help) ? optarg->help : "", allow_buildmode) != -1)) {
28912892
cli_add_comphelp_entry(comphelp, tptr);
28922893
free_z(tptr);
2893-
} else if (asprintf(&tptr, " %-20s %s%s", tptr, (optarg->help) ? optarg->help : "", allow_buildmode) != -1) {
2894+
} else if (asprintf(&tptr, " %-20s %s%s", tname, (optarg->help) ? optarg->help : "", allow_buildmode) != -1) {
28942895
cli_add_comphelp_entry(comphelp, tptr);
28952896
free_z(tptr);
28962897
}
2898+
free_z(tname);
28972899
} else if (lastchar == CTRL('I')) {
28982900
if (get_completions) {
28992901
(*get_completions)(cli, optarg->name, next_word, comphelp);

0 commit comments

Comments
 (0)