diff mbox series

selftests/dma:Fix a resource leak

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

Commit Message

Zhu Jun July 10, 2024, 6:30 a.m. UTC
The opened file should be closed in main(), 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/dma/dma_map_benchmark.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Shuah Khan July 10, 2024, 3:48 p.m. UTC | #1
On 7/10/24 00:30, Zhu Jun wrote:
> The opened file should be closed in main(), 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/dma/dma_map_benchmark.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/tools/testing/selftests/dma/dma_map_benchmark.c b/tools/testing/selftests/dma/dma_map_benchmark.c
> index 5c997f17fcbd..3fcea00961c0 100644
> --- a/tools/testing/selftests/dma/dma_map_benchmark.c
> +++ b/tools/testing/selftests/dma/dma_map_benchmark.c
> @@ -114,6 +114,7 @@ int main(int argc, char **argv)
>   	map.granule = granule;
>   
>   	if (ioctl(fd, cmd, &map)) {
> +		close(fd);
>   		perror("ioctl");
>   		exit(1);
>   	}
> @@ -125,5 +126,7 @@ int main(int argc, char **argv)
>   	printf("average unmap latency(us):%.1f standard deviation:%.1f\n",
>   			map.avg_unmap_100ns/10.0, map.unmap_stddev/10.0);
>   
> +	close(fd);
> +
>   	return 0;
>   }

Files get closed when this process exits. There is no need
to make this change.

thanks,
-- Shuah
diff mbox series

Patch

diff --git a/tools/testing/selftests/dma/dma_map_benchmark.c b/tools/testing/selftests/dma/dma_map_benchmark.c
index 5c997f17fcbd..3fcea00961c0 100644
--- a/tools/testing/selftests/dma/dma_map_benchmark.c
+++ b/tools/testing/selftests/dma/dma_map_benchmark.c
@@ -114,6 +114,7 @@  int main(int argc, char **argv)
 	map.granule = granule;
 
 	if (ioctl(fd, cmd, &map)) {
+		close(fd);
 		perror("ioctl");
 		exit(1);
 	}
@@ -125,5 +126,7 @@  int main(int argc, char **argv)
 	printf("average unmap latency(us):%.1f standard deviation:%.1f\n",
 			map.avg_unmap_100ns/10.0, map.unmap_stddev/10.0);
 
+	close(fd);
+
 	return 0;
 }