perf drm_pmu: Prevent resource leak in for_each_drm_fdinfo_in_dir()
PATCH 1/1 perf drm_pmu: Prevent resource leak in for_each_drm_fdinfo_in_dir()
Close fdinfo_dir_fd and fd_dir prior to exit, in the event of cb() error.
--- tools/perf/util/drm_pmu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/perf/util/drm_pmu.c +4 -4
@@ -403,7 +403,7 @@ static int for_each_drm_fdinfo_in_dir(int (*cb)(void *args, int fdinfo_dir_fd, cDIR *fd_dir;struct dirent *fd_entry;int fd_dir_fd, fdinfo_dir_fd =-1 ; - +int ret =0 ;scnprintf (buf,sizeof (buf),"%s/fd" , pid_name); fd_dir_fd =openat (proc_dir, buf,O_DIRECTORY );
@@ -418,7 +418,6 @@ static int for_each_drm_fdinfo_in_dir(int (*cb)(void *args, int fdinfo_dir_fd, cstruct stat stat;unsigned int minor;bool is_dup = false; -int ret;if (fd_entry->d_type !=DT_LNK )continue ;
@@ -458,12 +457,13 @@ static int for_each_drm_fdinfo_in_dir(int (*cb)(void *args, int fdinfo_dir_fd, c } ret =cb (args, fdinfo_dir_fd, fd_entry->d_name);if (ret) -return ret; + goto out; } +out:if (fdinfo_dir_fd !=-1 )close (fdinfo_dir_fd);closedir (fd_dir); -return 0 ; +return ret; } static int for_each_drm_fdinfo(bool skip_all_duplicates,
Signature · 1 line
2.43.0
Hello,
Quoted 4 lines · Sergio Perez Gonzalez
Close
fdinfo_dir_fdandfd_dirprior to exit, in the event ofcb()error.Signed-off-by Sergio Perez Gonzalez <[email protected]>
Only a nitpick below.
Quoted 26 lines
--- tools/perf/util/drm_pmu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)tools/perf/util/drm_pmu.c +1
-2@@ -403,7 +403,7 @@ static int for_each_drm_fdinfo_in_dir(int (*cb)(void *args, int fdinfo_dir_fd, cDIR *fd_dir;struct dirent *fd_entry;int fd_dir_fd, fdinfo_dir_fd =-1 ; - +int ret =0 ;scnprintf (buf,sizeof (buf),"%s/fd" , pid_name); fd_dir_fd =openat (proc_dir, buf,O_DIRECTORY );@@ -418,7 +418,6 @@ static int for_each_drm_fdinfo_in_dir(int (*cb)(void *args, int fdinfo_dir_fd, cstruct stat stat;unsigned int minor;bool is_dup = false; -int ret;if (fd_entry->d_type !=DT_LNK )continue ;
tools/perf/util/drm_pmu.c static int for_each_drm_fdinfo_in_dir(int (*cb)(void *args, int fdinfo_dir_fd, c · line 460
Quoted 5 lines
tools/perf/util/drm_pmu.c +1
-1@@ -458,12 +457,13 @@ static int for_each_drm_fdinfo_in_dir(int (*cb)(void *args, int fdinfo_dir_fd, c } ret =cb (args, fdinfo_dir_fd, fd_entry->d_name);if (ret) -return ret; + goto out;
It could be just 'break'.
Thanks,
Namhyung
Quoted 13 lines
tools/perf/util/drm_pmu.c +2
-1} +out:if (fdinfo_dir_fd !=-1 )close (fdinfo_dir_fd);closedir (fd_dir); -return 0 ; +return ret; } static int for_each_drm_fdinfo(bool skip_all_duplicates,Signature · 1 line
2.43.0
Namhyung Kim
maintainerQuoted 9 lines · Namhyung Kim
Hello,
Quoted 4 lines · Sergio Perez Gonzalez
Close
fdinfo_dir_fdandfd_dirprior to exit, in the event ofcb()error.Signed-off-by Sergio Perez Gonzalez <[email protected]>Acked-by Namhyung Kim <[email protected]>
Just found another fix was posted already:
https://lore.kernel.org/r/[email protected]
Thanks,
Namhyung
Quoted 54 lines
Only a nitpick below.
Quoted 26 lines
--- tools/perf/util/drm_pmu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)tools/perf/util/drm_pmu.c +1
-2@@ -403,7 +403,7 @@ static int for_each_drm_fdinfo_in_dir(int (*cb)(void *args, int fdinfo_dir_fd, cDIR *fd_dir;struct dirent *fd_entry;int fd_dir_fd, fdinfo_dir_fd =-1 ; - +int ret =0 ;scnprintf (buf,sizeof (buf),"%s/fd" , pid_name); fd_dir_fd =openat (proc_dir, buf,O_DIRECTORY );@@ -418,7 +418,6 @@ static int for_each_drm_fdinfo_in_dir(int (*cb)(void *args, int fdinfo_dir_fd, cstruct stat stat;unsigned int minor;bool is_dup = false; -int ret;if (fd_entry->d_type !=DT_LNK )continue ;tools/perf/util/drm_pmu.c static int for_each_drm_fdinfo_in_dir(int (*cb)(void *args, int fdinfo_dir_fd, c · line 460
Quoted 5 lines
tools/perf/util/drm_pmu.c +1
-1@@ -458,12 +457,13 @@ static int for_each_drm_fdinfo_in_dir(int (*cb)(void *args, int fdinfo_dir_fd, c } ret =cb (args, fdinfo_dir_fd, fd_entry->d_name);if (ret) -return ret; + goto out;It could be just 'break'.
Thanks,
NamhyungQuoted 13 lines
tools/perf/util/drm_pmu.c +2
-1} +out:if (fdinfo_dir_fd !=-1 )close (fdinfo_dir_fd);closedir (fd_dir); -return 0 ; +return ret; } static int for_each_drm_fdinfo(bool skip_all_duplicates,Signature · 1 line
2.43.0