aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@gmail.com>2019-11-03 10:43:43 +0100
committerNikolaus Rath <Nikolaus@rath.org>2019-11-03 09:43:43 +0000
commitfa0981fe80b037cdd923f3d87157e78f9e1222a9 (patch)
treeb2f333a37f8d43a3c2db3ff99e0091bf4e45bc45 /example
parent74596e2929c9b9b065f90d04ab7a2232652c64c4 (diff)
downloadlibfuse-fa0981fe80b037cdd923f3d87157e78f9e1222a9.tar.gz
passthrough_ll: drop lo_dirp->fd field (#464)
fdopendir(3) takes ownership of the file descriptor. The presence of the lo_dirp->fd field could lead to someone incorrectly adding a close(d->fd) cleanup call in the future. Do not store the file descriptor in struct lo_dirp since it is unused. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Diffstat (limited to 'example')
-rw-r--r--example/passthrough_ll.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/example/passthrough_ll.c b/example/passthrough_ll.c
index 4e37602..0f1fda5 100644
--- a/example/passthrough_ll.c
+++ b/example/passthrough_ll.c
@@ -596,7 +596,6 @@ static void lo_readlink(fuse_req_t req, fuse_ino_t ino)
}
struct lo_dirp {
- int fd;
DIR *dp;
struct dirent *entry;
off_t offset;
@@ -611,15 +610,18 @@ static void lo_opendir(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi
{
int error = ENOMEM;
struct lo_data *lo = lo_data(req);
- struct lo_dirp *d = calloc(1, sizeof(struct lo_dirp));
+ struct lo_dirp *d;
+ int fd;
+
+ d = calloc(1, sizeof(struct lo_dirp));
if (d == NULL)
goto out_err;
- d->fd = openat(lo_fd(req, ino), ".", O_RDONLY);
- if (d->fd == -1)
+ fd = openat(lo_fd(req, ino), ".", O_RDONLY);
+ if (fd == -1)
goto out_errno;
- d->dp = fdopendir(d->fd);
+ d->dp = fdopendir(fd);
if (d->dp == NULL)
goto out_errno;
@@ -636,8 +638,8 @@ out_errno:
error = errno;
out_err:
if (d) {
- if (d->fd != -1)
- close(d->fd);
+ if (fd != -1)
+ close(fd);
free(d);
}
fuse_reply_err(req, error);