perf report: Fix memory leaks around perf_tip()
[ Upstream commit d9fc706108c15f8bc2d4ccccf8e50f74830fabd9 ] perf_tip() may allocate memory or use a literal, this means memory wasn't freed if allocated. Change the API so that literals aren't used. At the same time add missing frees for system_path. These issues were spotted using leak sanitizer. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lore.kernel.org/lkml/20211118073804.2149974-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:

committed by
Greg Kroah-Hartman

parent
a4c17ebdd6
commit
ff061b5bda
@@ -379,32 +379,32 @@ fetch_kernel_version(unsigned int *puint, char *str,
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *perf_tip(const char *dirpath)
|
||||
int perf_tip(char **strp, const char *dirpath)
|
||||
{
|
||||
struct strlist *tips;
|
||||
struct str_node *node;
|
||||
char *tip = NULL;
|
||||
struct strlist_config conf = {
|
||||
.dirname = dirpath,
|
||||
.file_only = true,
|
||||
};
|
||||
int ret = 0;
|
||||
|
||||
*strp = NULL;
|
||||
tips = strlist__new("tips.txt", &conf);
|
||||
if (tips == NULL)
|
||||
return errno == ENOENT ? NULL :
|
||||
"Tip: check path of tips.txt or get more memory! ;-p";
|
||||
return -errno;
|
||||
|
||||
if (strlist__nr_entries(tips) == 0)
|
||||
goto out;
|
||||
|
||||
node = strlist__entry(tips, random() % strlist__nr_entries(tips));
|
||||
if (asprintf(&tip, "Tip: %s", node->s) < 0)
|
||||
tip = (char *)"Tip: get more memory! ;-)";
|
||||
if (asprintf(strp, "Tip: %s", node->s) < 0)
|
||||
ret = -ENOMEM;
|
||||
|
||||
out:
|
||||
strlist__delete(tips);
|
||||
|
||||
return tip;
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *perf_exe(char *buf, int len)
|
||||
|
Reference in New Issue
Block a user