Re: [PATCH] dma/dma_map_benchmark: fix fd leak on error and exit

From: Qinxin Xia

Date: Sun May 24 2026 - 21:44:41 EST




On 2026/5/21 17:32:36, David Laight <david.laight.linux@xxxxxxxxx> wrote:
On Thu, 21 May 2026 16:02:41 +0800
2564278112@xxxxxx wrote:

From: Wang Jiang <jiangwang@xxxxxxxxxx>

Close the file descriptor when ioctl fails and on normal exit
to fix file descriptor leak.

There isn't a leak, it is all tidied up by the kernel.

-- David


Signed-off-by: Wang Jiang <jiangwang@xxxxxxxxxx>
---
tools/dma/dma_map_benchmark.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/tools/dma/dma_map_benchmark.c b/tools/dma/dma_map_benchmark.c
index eab0ac611a23..bdb8a837f020 100644
--- a/tools/dma/dma_map_benchmark.c
+++ b/tools/dma/dma_map_benchmark.c
@@ -130,6 +130,7 @@ int main(int argc, char **argv)
if (ioctl(fd, cmd, &map)) {
perror("ioctl");
+ close(fd);
exit(1);
}
@@ -140,5 +141,6 @@ 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;
}


Thanks for the patch, but as David said, the kernel cleans up on exit,
so no leak. I'd prefer to leave it as is. :-)

--
Thanks,
Qinxin