diff mbox series

selftests/rtc:Fix a resource leak

Message ID 20240710060743.4691-1-zhujun2@cmss.chinamobile.com (mailing list archive)
State Rejected
Headers show
Series selftests/rtc:Fix a resource leak | expand

Commit Message

Zhu Jun July 10, 2024, 6:07 a.m. UTC
The opened file should be closed before exit, otherwise resource leak
will occur that this problem was discovered by reading code

Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
---
 tools/testing/selftests/rtc/setdate.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Alexandre Belloni July 10, 2024, 7:16 a.m. UTC | #1
On 09/07/2024 23:07:43-0700, Zhu Jun wrote:
> The opened file should be closed before exit, otherwise resource leak
> will occur that this problem was discovered by reading code

Can you elaborate on the leak? All the fds are getting closed on exit.

> 
> Signed-off-by: Zhu Jun <zhujun2@cmss.chinamobile.com>
> ---
>  tools/testing/selftests/rtc/setdate.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/tools/testing/selftests/rtc/setdate.c b/tools/testing/selftests/rtc/setdate.c
> index b303890b3de2..17a00affb0ec 100644
> --- a/tools/testing/selftests/rtc/setdate.c
> +++ b/tools/testing/selftests/rtc/setdate.c
> @@ -65,6 +65,7 @@ int main(int argc, char **argv)
>  	retval = ioctl(fd, RTC_RD_TIME, &current);
>  	if (retval == -1) {
>  		perror("RTC_RD_TIME ioctl");
> +		close(fd);
>  		exit(errno);
>  	}
>  
> -- 
> 2.17.1
> 
> 
>
diff mbox series

Patch

diff --git a/tools/testing/selftests/rtc/setdate.c b/tools/testing/selftests/rtc/setdate.c
index b303890b3de2..17a00affb0ec 100644
--- a/tools/testing/selftests/rtc/setdate.c
+++ b/tools/testing/selftests/rtc/setdate.c
@@ -65,6 +65,7 @@  int main(int argc, char **argv)
 	retval = ioctl(fd, RTC_RD_TIME, &current);
 	if (retval == -1) {
 		perror("RTC_RD_TIME ioctl");
+		close(fd);
 		exit(errno);
 	}