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]
Date:   Tue, 6 Feb 2018 16:09:02 -0300
From:   Arnaldo Carvalho de Melo <acme@...nel.org>
To:     Jiri Olsa <jolsa@...nel.org>
Cc:     lkml <linux-kernel@...r.kernel.org>,
        Ingo Molnar <mingo@...nel.org>,
        Namhyung Kim <namhyung@...nel.org>,
        David Ahern <dsahern@...il.com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Peter Zijlstra <a.p.zijlstra@...llo.nl>
Subject: Re: [PATCH 07/17] perf tools: Free root_dir in machine__init error
 path

Em Tue, Feb 06, 2018 at 07:18:03PM +0100, Jiri Olsa escreveu:
> Freeing root_dir in machine__init error path.
> 
> Link: http://lkml.kernel.org/n/tip-ng92slsanexqw7h1d6sadnj7@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@...nel.org>
> ---
>  tools/perf/util/machine.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
> index b05a67464c03..e300a643f65b 100644
> --- a/tools/perf/util/machine.c
> +++ b/tools/perf/util/machine.c
> @@ -50,6 +50,8 @@ static void machine__threads_init(struct machine *machine)
>  
>  int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
>  {
> +	int err = -ENOMEM;
> +
>  	memset(machine, 0, sizeof(*machine));
>  	map_groups__init(&machine->kmaps, machine);
>  	RB_CLEAR_NODE(&machine->rb_node);
> @@ -79,7 +81,7 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
>  		char comm[64];
>  
>  		if (thread == NULL)
> -			return -ENOMEM;
> +			goto out;
>  
>  		snprintf(comm, sizeof(comm), "[guest/%d]", pid);
>  		thread__set_comm(thread, comm, 0);
> @@ -87,7 +89,11 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
>  	}
>  
>  	machine->current_tid = NULL;
> +	err = 0;
>  
> +out:
> +	if (err)
> +		free(machine->root_dir);

In these cases, i.e. freeing something inside some other struct, its
better to use:

		zfree(&machine->root_dir);

>  	return 0;
>  }
>  
> -- 
> 2.13.6

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ