Skip to contentSkip to conversation

perf tools: Fix resources leak in perf_data__open_dir

PATCH Applied Miaoqian Lin 3 participants 3 messages Dec 29, 2022 – Jan 2, 2023 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf tools: Fix resources leak in perf_data__open_dir

In perf_data__open_dir(), opendir() opens the directory stream. Add missing closedir() to release it after use.

Fixes eb6176709b23 ("perf data: Add perf_data__open_dir_data function")
---
 tools/perf/util/data.c | 2 ++
 1 file changed, 2 insertions(+)
tools/perf/util/data.c +2 -0
index a7f68c309545..fc16299c915f 100644
@@ -132,6 +132,7 @@ int perf_data__open_dir(struct perf_data *data)
 		file->size = st.st_size;
 	}
 
+	closedir(dir);
 	if (!files)
 		return -EINVAL;
 
@@ -140,6 +141,7 @@ int perf_data__open_dir(struct perf_data *data)
 	return 0;
 
 out_err:
+	closedir(dir);
 	close_dir(files, nr);
 	return ret;
 }
Signature · 1 line
2.25.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Miaoqian Lin

In perf_data__open_dir(), opendir() opens the directory stream. Add missing closedir() to release it after use.

Fixes eb6176709b23 ("perf data: Add perf_data__open_dir_data function")
Quoted 24 lines
---
 tools/perf/util/data.c | 2 ++
 1 file changed, 2 insertions(+)
tools/perf/util/data.c +2 -0
index a7f68c309545..fc16299c915f 100644
@@ -132,6 +132,7 @@ int perf_data__open_dir(struct perf_data *data)
 		file->size = st.st_size;
 	}
 
+	closedir(dir);
 	if (!files)
 		return -EINVAL;
 
@@ -140,6 +141,7 @@ int perf_data__open_dir(struct perf_data *data)
 	return 0;
 
 out_err:
+	closedir(dir);
 	close_dir(files, nr);
 	return ret;
 }
maintainer Applied
#2 lore raw

Em Thu, Dec 29, 2022 at 01:27:39PM +0200, Adrian Hunter escreveu:

Quoted 8 lines · Miaoqian Lin
Quoted 5 lines

In perf_data__open_dir(), opendir() opens the directory stream. Add missing closedir() to release it after use.

Fixes eb6176709b23 ("perf data: Add perf_data__open_dir_data function")

Thanks, applied.

- Arnaldo

Quoted 24 lines
Quoted 24 lines
---
 tools/perf/util/data.c | 2 ++
 1 file changed, 2 insertions(+)
tools/perf/util/data.c +2 -0
index a7f68c309545..fc16299c915f 100644
@@ -132,6 +132,7 @@ int perf_data__open_dir(struct perf_data *data)
 		file->size = st.st_size;
 	}
 
+	closedir(dir);
 	if (!files)
 		return -EINVAL;
 
@@ -140,6 +141,7 @@ int perf_data__open_dir(struct perf_data *data)
 	return 0;
 
 out_err:
+	closedir(dir);
 	close_dir(files, nr);
 	return ret;
 }
Signature · 1 line
- Arnaldo