Re: [PATCH] perf namespaces: check newns before free
From: Thomas Richter
Date: Mon Sep 09 2024 - 10:12:26 EST
On 9/3/24 11:12, zhangjiao2 wrote:
> From: zhang jiao <zhangjiao2@xxxxxxxxxxxxxxxxxxxx>
>
> Since newns can be NULL, check it before free
>
> Signed-off-by: zhang jiao <zhangjiao2@xxxxxxxxxxxxxxxxxxxx>
> ---
> tools/perf/util/namespaces.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/namespaces.c b/tools/perf/util/namespaces.c
> index cb185c5659d6..49e20e0a567a 100644
> --- a/tools/perf/util/namespaces.c
> +++ b/tools/perf/util/namespaces.c
> @@ -135,7 +135,8 @@ int nsinfo__init(struct nsinfo *nsi)
> &RC_CHK_ACCESS(nsi)->in_pidns, spath);
>
> out:
> - free(newns);
> + if (newns)
> + free(newns);
> return rv;
> }
>
Ins't zfree() to proper function to use? Also zfree() calls free()
from the C library which can handle a NULL pointer?
Just my opinion.
--
Thomas Richter, Dept 3303, IBM s390 Linux Development, Boeblingen, Germany
--
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Wolfgang Wendt
Geschäftsführung: David Faller
Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294