From 2a87b64af7cdff331f62cff37d3b8528299d1708 Mon Sep 17 00:00:00 2001 From: Zhiqiang Liu Date: Thu, 5 Nov 2020 18:00:32 +0800 Subject: [PATCH] ioctl_client.c: fix potential fd leakage problem In ioctl_client.c, fd is not closed before return, thus it will cause fd leakage problem. Signed-off-by: Zhiqiang Liu Signed-off-by: Haotian Li --- example/ioctl_client.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/example/ioctl_client.c b/example/ioctl_client.c index d93f549..dcb18cc 100644 --- a/example/ioctl_client.c +++ b/example/ioctl_client.c @@ -41,6 +41,7 @@ int main(int argc, char **argv) { size_t size; int fd; + int ret = 0; if (argc < 2) { fprintf(stderr, "%s", usage); @@ -56,15 +57,19 @@ int main(int argc, char **argv) if (argc == 2) { if (ioctl(fd, FIOC_GET_SIZE, &size)) { perror("ioctl"); - return 1; + ret = 1; + goto out; } printf("%zu\n", size); } else { size = strtoul(argv[2], NULL, 0); if (ioctl(fd, FIOC_SET_SIZE, &size)) { perror("ioctl"); - return 1; + ret = 1; + goto out; } } - return 0; +out: + close(fd); + return ret; } -- 2.30.2