mirror of
https://github.com/nxp-imx/linux-imx.git
synced 2025-07-11 20:05:22 +02:00
libsubcmd: Fix parse-options memory leak
[ Upstream commit230a7a71f9
] If a usage string is built in parse_options_subcommand, also free it. Fixes:901421a5bd
("perf tools: Remove subcmd dependencies on strbuf") Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Josh Poimboeuf <jpoimboe@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/r/20240509052015.1914670-1-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
70d6dca403
commit
c546fef47c
|
@ -633,11 +633,10 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *o
|
||||||
const char *const subcommands[], const char *usagestr[], int flags)
|
const char *const subcommands[], const char *usagestr[], int flags)
|
||||||
{
|
{
|
||||||
struct parse_opt_ctx_t ctx;
|
struct parse_opt_ctx_t ctx;
|
||||||
|
char *buf = NULL;
|
||||||
|
|
||||||
/* build usage string if it's not provided */
|
/* build usage string if it's not provided */
|
||||||
if (subcommands && !usagestr[0]) {
|
if (subcommands && !usagestr[0]) {
|
||||||
char *buf = NULL;
|
|
||||||
|
|
||||||
astrcatf(&buf, "%s %s [<options>] {", subcmd_config.exec_name, argv[0]);
|
astrcatf(&buf, "%s %s [<options>] {", subcmd_config.exec_name, argv[0]);
|
||||||
|
|
||||||
for (int i = 0; subcommands[i]; i++) {
|
for (int i = 0; subcommands[i]; i++) {
|
||||||
|
@ -679,7 +678,10 @@ int parse_options_subcommand(int argc, const char **argv, const struct option *o
|
||||||
astrcatf(&error_buf, "unknown switch `%c'", *ctx.opt);
|
astrcatf(&error_buf, "unknown switch `%c'", *ctx.opt);
|
||||||
usage_with_options(usagestr, options);
|
usage_with_options(usagestr, options);
|
||||||
}
|
}
|
||||||
|
if (buf) {
|
||||||
|
usagestr[0] = NULL;
|
||||||
|
free(buf);
|
||||||
|
}
|
||||||
return parse_options_end(&ctx);
|
return parse_options_end(&ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user