lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87oblibb7r.fsf@sejong.aot.lge.com>
Date:	Fri, 07 Sep 2012 15:26:00 +0900
From:	Namhyung Kim <namhyung@...nel.org>
To:	liang xie <xieliang007@...il.com>
Cc:	acme@...stprotocols.net, a.p.zijlstra@...llo.nl, mingo@...e.hu,
	paulus@...ba.org, balbi@...com, linux-perf-users@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] A trivial memory leak fix while calling system_path

Hi, liang

On Fri, 7 Sep 2012 11:34:49 +0800, liang xie wrote:
> A trivial memory leak fix while calling system_path
>
> Since v1: Remove an unnecessary null pointer check per Felipe's comments
>
> Signed-off-by: Liang Xie <xieliang@...omi.com>
> ---
>  tools/perf/util/exec_cmd.c |    4 +++-
>  tools/perf/util/help.c     |    1 +
>  2 files changed, 4 insertions(+), 1 deletions(-)
>
> diff --git a/tools/perf/util/exec_cmd.c b/tools/perf/util/exec_cmd.c
> index 7adf4ad..d041407 100644
> --- a/tools/perf/util/exec_cmd.c
> +++ b/tools/perf/util/exec_cmd.c
> @@ -83,8 +83,9 @@ void setup_path(void)
>  {
>  	const char *old_path = getenv("PATH");
>  	struct strbuf new_path = STRBUF_INIT;
> +	const char *exec_path = perf_exec_path();
>
> -	add_path(&new_path, perf_exec_path());
> +	add_path(&new_path, exec_path);
>  	add_path(&new_path, argv0_path);
>
>  	if (old_path)
> @@ -95,6 +96,7 @@ void setup_path(void)
>  	setenv("PATH", new_path.buf, 1);
>
>  	strbuf_release(&new_path);
> +	free((void *)exec_path);
>  }

The problem is that perf_exec_path() can return a non-dynamically
allocated string (e.g. command line argument or environment string) and
currently we cannot know where the returned string is came from.

It might cause much more troubles when you free that kind of string than
just leaking a couple of bytes IMHO.

Thanks,
Namhyung

>
>  static const char **prepare_perf_cmd(const char **argv)
> diff --git a/tools/perf/util/help.c b/tools/perf/util/help.c
> index 6f2975a..798f66d 100644
> --- a/tools/perf/util/help.c
> +++ b/tools/perf/util/help.c
> @@ -187,6 +187,7 @@ void load_command_list(const char *prefix,
>  		uniq(other_cmds);
>  	}
>  	exclude_cmds(other_cmds, main_cmds);
> +	free((void *)exec_path);
>  }
>
>  void list_commands(const char *title, struct cmdnames *main_cmds,
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ