linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf namespaces: check newns before free
@ 2024-09-03  9:12 zhangjiao2
  2024-09-05  4:10 ` Namhyung Kim
  2024-09-09 14:12 ` Thomas Richter
  0 siblings, 2 replies; 3+ messages in thread
From: zhangjiao2 @ 2024-09-03  9:12 UTC (permalink / raw)
  To: peterz; +Cc: mingo, acme, namhyung, linux-perf-users, linux-kernel, zhang jiao

From: zhang jiao <zhangjiao2@cmss.chinamobile.com>

Since newns can be NULL, check it before free

Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
---
 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;
 }
 
-- 
2.33.0




^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf namespaces: check newns before free
  2024-09-03  9:12 [PATCH] perf namespaces: check newns before free zhangjiao2
@ 2024-09-05  4:10 ` Namhyung Kim
  2024-09-09 14:12 ` Thomas Richter
  1 sibling, 0 replies; 3+ messages in thread
From: Namhyung Kim @ 2024-09-05  4:10 UTC (permalink / raw)
  To: zhangjiao2; +Cc: peterz, mingo, acme, linux-perf-users, linux-kernel

Hello,

On Tue, Sep 03, 2024 at 05:12:08PM +0800, zhangjiao2 wrote:
> From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
> 
> Since newns can be NULL, check it before free
> 
> Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
> ---
>  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);

It's ok to call free(NULL).

Thanks,
Namhyung


>  	return rv;
>  }
>  
> -- 
> 2.33.0
> 
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf namespaces: check newns before free
  2024-09-03  9:12 [PATCH] perf namespaces: check newns before free zhangjiao2
  2024-09-05  4:10 ` Namhyung Kim
@ 2024-09-09 14:12 ` Thomas Richter
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Richter @ 2024-09-09 14:12 UTC (permalink / raw)
  To: zhangjiao2, peterz; +Cc: mingo, acme, namhyung, linux-perf-users, linux-kernel

On 9/3/24 11:12, zhangjiao2 wrote:
> From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
> 
> Since newns can be NULL, check it before free
> 
> Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
> ---
>  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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-09-09 14:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-03  9:12 [PATCH] perf namespaces: check newns before free zhangjiao2
2024-09-05  4:10 ` Namhyung Kim
2024-09-09 14:12 ` Thomas Richter

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).