summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhiqiang Liu <liuzhiqiang26@huawei.com>2020-11-05 18:00:32 +0800
committerNikolaus Rath <Nikolaus@rath.org>2020-11-06 19:26:03 +0000
commit2a87b64af7cdff331f62cff37d3b8528299d1708 (patch)
treea900937a95f5c819c55023e85ae42af1fc645deb
parent5670dde86ce311bfc68b0398cda545b3230787e8 (diff)
downloadfuse-2a87b64af7cdff331f62cff37d3b8528299d1708.tar.gz
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 <liuzhiqiang26@huawei.com> Signed-off-by: Haotian Li <lihaotian9@huawei.com>
-rw-r--r--example/ioctl_client.c11
1 files 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;
}