kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] perf header: Fix possible memory leak when using do_read_string
@ 2020-07-02 15:07 Markus Elfring
  0 siblings, 0 replies; only message in thread
From: Markus Elfring @ 2020-07-02 15:07 UTC (permalink / raw)
  To: tongtiangen, kernel-janitors
  Cc: linux-kernel, Alexander Shishkin, Arnaldo Carvalho de Melo,
	Ingo Molnar, Jiri Olsa, Kan Liang, Mark Rutland,
	Masami Hiramatsu, Namhyung Kim, Peter Zijlstra, Wei Yongjun

> In the header.c file, some functions allocate memory after using
> do_read_string, but the corresponding memory is not released after
> subsequent processing errors, causing memory leaks.

I suggest to choose an imperative wording for this change description.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id=cd77006e01b3198c75fb7819b3d0ff89709539bb#n151> +++ b/tools/perf/util/header.c
> @@ -2307,8 +2307,10 @@  static int process_cpu_topology(struct feat_fd *ff, void *data __maybe_unused)
>  			goto error;
>
>  		/* include a NULL character at the end */
> -		if (strbuf_add(&sb, str, strlen(str) + 1) < 0)
> +		if (strbuf_add(&sb, str, strlen(str) + 1) < 0) {
> +			free(str);
>  			goto error;
> +		}
>  		size += string_size(str);
…

I propose to add the jump target “free_str” for nicer exception handling
in this function implementation.

Regards,
Markus

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-07-02 15:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-02 15:07 [PATCH] perf header: Fix possible memory leak when using do_read_string Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).