All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf tools: fix resource leak of closedir() on the error paths
@ 2019-10-15  8:30 Yunfeng Ye
  2019-10-15  8:44 ` Jiri Olsa
  2019-10-21  6:26 ` [tip: perf/urgent] perf tools: Fix " tip-bot2 for Yunfeng Ye
  0 siblings, 2 replies; 4+ messages in thread
From: Yunfeng Ye @ 2019-10-15  8:30 UTC (permalink / raw)
  To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
	namhyung, ast, daniel, kafai, songliubraving, yhs, ilubashe, ak,
	yeyunfeng, kan.liang, alexey.budankov
  Cc: linux-kernel, netdev, bpf, hushiyuan, linfeilong

Both build_mem_topology() and rm_rf_depth_pat() have resource leak of
closedir() on the error paths.

Fix this by calling closedir() before function returns.

Fixes: e2091cedd51b ("perf tools: Add MEM_TOPOLOGY feature to perf data file")
Fixes: cdb6b0235f17 ("perf tools: Add pattern name checking to rm_rf")
Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
---
 tools/perf/util/header.c | 4 +++-
 tools/perf/util/util.c   | 6 ++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 86d9396..becc2d1 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1296,8 +1296,10 @@ static int build_mem_topology(struct memory_node *nodes, u64 size, u64 *cntp)
 			continue;

 		if (WARN_ONCE(cnt >= size,
-			      "failed to write MEM_TOPOLOGY, way too many nodes\n"))
+			"failed to write MEM_TOPOLOGY, way too many nodes\n")) {
+			closedir(dir);
 			return -1;
+		}

 		ret = memory_node__read(&nodes[cnt++], idx);
 	}
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 5eda6e1..ae56c76 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -154,8 +154,10 @@ static int rm_rf_depth_pat(const char *path, int depth, const char **pat)
 		if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
 			continue;

-		if (!match_pat(d->d_name, pat))
-			return -2;
+		if (!match_pat(d->d_name, pat)) {
+			ret =  -2;
+			break;
+		}

 		scnprintf(namebuf, sizeof(namebuf), "%s/%s",
 			  path, d->d_name);
-- 
2.7.4.huawei.3


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

* Re: [PATCH] perf tools: fix resource leak of closedir() on the error paths
  2019-10-15  8:30 [PATCH] perf tools: fix resource leak of closedir() on the error paths Yunfeng Ye
@ 2019-10-15  8:44 ` Jiri Olsa
  2019-10-15 14:58   ` Arnaldo Carvalho de Melo
  2019-10-21  6:26 ` [tip: perf/urgent] perf tools: Fix " tip-bot2 for Yunfeng Ye
  1 sibling, 1 reply; 4+ messages in thread
From: Jiri Olsa @ 2019-10-15  8:44 UTC (permalink / raw)
  To: Yunfeng Ye
  Cc: peterz, mingo, acme, mark.rutland, alexander.shishkin, namhyung,
	ast, daniel, kafai, songliubraving, yhs, ilubashe, ak, kan.liang,
	alexey.budankov, linux-kernel, netdev, bpf, hushiyuan, linfeilong

On Tue, Oct 15, 2019 at 04:30:08PM +0800, Yunfeng Ye wrote:
> Both build_mem_topology() and rm_rf_depth_pat() have resource leak of
> closedir() on the error paths.
> 
> Fix this by calling closedir() before function returns.
> 
> Fixes: e2091cedd51b ("perf tools: Add MEM_TOPOLOGY feature to perf data file")
> Fixes: cdb6b0235f17 ("perf tools: Add pattern name checking to rm_rf")

guilty as charged ;-)

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka


> Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
> ---
>  tools/perf/util/header.c | 4 +++-
>  tools/perf/util/util.c   | 6 ++++--
>  2 files changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index 86d9396..becc2d1 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -1296,8 +1296,10 @@ static int build_mem_topology(struct memory_node *nodes, u64 size, u64 *cntp)
>  			continue;
> 
>  		if (WARN_ONCE(cnt >= size,
> -			      "failed to write MEM_TOPOLOGY, way too many nodes\n"))
> +			"failed to write MEM_TOPOLOGY, way too many nodes\n")) {
> +			closedir(dir);
>  			return -1;
> +		}
> 
>  		ret = memory_node__read(&nodes[cnt++], idx);
>  	}
> diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
> index 5eda6e1..ae56c76 100644
> --- a/tools/perf/util/util.c
> +++ b/tools/perf/util/util.c
> @@ -154,8 +154,10 @@ static int rm_rf_depth_pat(const char *path, int depth, const char **pat)
>  		if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
>  			continue;
> 
> -		if (!match_pat(d->d_name, pat))
> -			return -2;
> +		if (!match_pat(d->d_name, pat)) {
> +			ret =  -2;
> +			break;
> +		}
> 
>  		scnprintf(namebuf, sizeof(namebuf), "%s/%s",
>  			  path, d->d_name);
> -- 
> 2.7.4.huawei.3
> 

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

* Re: [PATCH] perf tools: fix resource leak of closedir() on the error paths
  2019-10-15  8:44 ` Jiri Olsa
@ 2019-10-15 14:58   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 4+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-10-15 14:58 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Yunfeng Ye, peterz, mingo, mark.rutland, alexander.shishkin,
	namhyung, ast, daniel, kafai, songliubraving, yhs, ilubashe, ak,
	kan.liang, alexey.budankov, linux-kernel, netdev, bpf, hushiyuan,
	linfeilong

Em Tue, Oct 15, 2019 at 10:44:51AM +0200, Jiri Olsa escreveu:
> On Tue, Oct 15, 2019 at 04:30:08PM +0800, Yunfeng Ye wrote:
> > Both build_mem_topology() and rm_rf_depth_pat() have resource leak of
> > closedir() on the error paths.
> > 
> > Fix this by calling closedir() before function returns.
> > 
> > Fixes: e2091cedd51b ("perf tools: Add MEM_TOPOLOGY feature to perf data file")
> > Fixes: cdb6b0235f17 ("perf tools: Add pattern name checking to rm_rf")
> 
> guilty as charged ;-)
> 
> Acked-by: Jiri Olsa <jolsa@kernel.org>

Thanks, applied to perf/urgent.

- Arnaldo

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

* [tip: perf/urgent] perf tools: Fix resource leak of closedir() on the error paths
  2019-10-15  8:30 [PATCH] perf tools: fix resource leak of closedir() on the error paths Yunfeng Ye
  2019-10-15  8:44 ` Jiri Olsa
@ 2019-10-21  6:26 ` tip-bot2 for Yunfeng Ye
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot2 for Yunfeng Ye @ 2019-10-21  6:26 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Yunfeng Ye, Jiri Olsa, Alexander Shishkin, Alexei Starovoitov,
	Alexey Budankov, Andi Kleen, Daniel Borkmann, Feilong Lin,
	Hu Shiyuan, Igor Lubashev, Kan Liang, Mark Rutland,
	Martin KaFai Lau, Namhyung Kim, Peter Zijlstra, Song Liu,
	Yonghong Song, Arnaldo Carvalho de Melo, Ingo Molnar,
	Borislav Petkov, linux-kernel

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     6080728ff8e9c9116e52e6f840152356ac2fea56
Gitweb:        https://git.kernel.org/tip/6080728ff8e9c9116e52e6f840152356ac2fea56
Author:        Yunfeng Ye <yeyunfeng@huawei.com>
AuthorDate:    Tue, 15 Oct 2019 16:30:08 +08:00
Committer:     Arnaldo Carvalho de Melo <acme@redhat.com>
CommitterDate: Tue, 15 Oct 2019 11:54:11 -03:00

perf tools: Fix resource leak of closedir() on the error paths

Both build_mem_topology() and rm_rf_depth_pat() have resource leaks of
closedir() on the error paths.

Fix this by calling closedir() before function returns.

Fixes: e2091cedd51b ("perf tools: Add MEM_TOPOLOGY feature to perf data file")
Fixes: cdb6b0235f17 ("perf tools: Add pattern name checking to rm_rf")
Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Feilong Lin <linfeilong@huawei.com>
Cc: Hu Shiyuan <hushiyuan@huawei.com>
Cc: Igor Lubashev <ilubashe@akamai.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Martin KaFai Lau <kafai@fb.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: Yonghong Song <yhs@fb.com>
Link: http://lore.kernel.org/lkml/cd5f7cd2-b80d-6add-20a1-32f4f43e0744@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/header.c | 4 +++-
 tools/perf/util/util.c   | 6 ++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 86d9396..becc2d1 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1296,8 +1296,10 @@ static int build_mem_topology(struct memory_node *nodes, u64 size, u64 *cntp)
 			continue;
 
 		if (WARN_ONCE(cnt >= size,
-			      "failed to write MEM_TOPOLOGY, way too many nodes\n"))
+			"failed to write MEM_TOPOLOGY, way too many nodes\n")) {
+			closedir(dir);
 			return -1;
+		}
 
 		ret = memory_node__read(&nodes[cnt++], idx);
 	}
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 5eda6e1..ae56c76 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -154,8 +154,10 @@ static int rm_rf_depth_pat(const char *path, int depth, const char **pat)
 		if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
 			continue;
 
-		if (!match_pat(d->d_name, pat))
-			return -2;
+		if (!match_pat(d->d_name, pat)) {
+			ret =  -2;
+			break;
+		}
 
 		scnprintf(namebuf, sizeof(namebuf), "%s/%s",
 			  path, d->d_name);

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

end of thread, other threads:[~2019-10-21  6:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-15  8:30 [PATCH] perf tools: fix resource leak of closedir() on the error paths Yunfeng Ye
2019-10-15  8:44 ` Jiri Olsa
2019-10-15 14:58   ` Arnaldo Carvalho de Melo
2019-10-21  6:26 ` [tip: perf/urgent] perf tools: Fix " tip-bot2 for Yunfeng Ye

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.