perf tools: Fix resources leak in perf_data__open_dir

Message ID 20221229090903.1402395-1-linmq006@gmail.com
State New
Headers
Series perf tools: Fix resources leak in perf_data__open_dir |

Commit Message

Miaoqian Lin Dec. 29, 2022, 9:09 a.m. UTC
  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")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 tools/perf/util/data.c | 2 ++
 1 file changed, 2 insertions(+)
  

Comments

Adrian Hunter Dec. 29, 2022, 11:27 a.m. UTC | #1
On 29/12/22 11:09, Miaoqian Lin wrote:
> 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")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>

Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  tools/perf/util/data.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
> index a7f68c309545..fc16299c915f 100644
> --- a/tools/perf/util/data.c
> +++ b/tools/perf/util/data.c
> @@ -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;
>  }
  
Arnaldo Carvalho de Melo Jan. 2, 2023, 2:46 p.m. UTC | #2
Em Thu, Dec 29, 2022 at 01:27:39PM +0200, Adrian Hunter escreveu:
> On 29/12/22 11:09, Miaoqian Lin wrote:
> > 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")
> > Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> 
> Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>

Thanks, applied.

- Arnaldo

 
> > ---
> >  tools/perf/util/data.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
> > index a7f68c309545..fc16299c915f 100644
> > --- a/tools/perf/util/data.c
> > +++ b/tools/perf/util/data.c
> > @@ -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;
> >  }
  

Patch

diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index a7f68c309545..fc16299c915f 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -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;
 }