puffs_null_node_fsync: don't leak directory handle
Directory handles returned by opendir must be closed by closedir. Also directory(3) says we mustn't close(2) descriptors returned by dirfd(3)
This commit is contained in:
parent
c022c48edf
commit
3896b31418
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: null.c,v 1.34 2019/09/23 12:00:57 christos Exp $ */
|
/* $NetBSD: null.c,v 1.35 2019/11/02 18:14:36 tnn Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#if !defined(lint)
|
#if !defined(lint)
|
||||||
__RCSID("$NetBSD: null.c,v 1.34 2019/09/23 12:00:57 christos Exp $");
|
__RCSID("$NetBSD: null.c,v 1.35 2019/11/02 18:14:36 tnn Exp $");
|
||||||
#endif /* !lint */
|
#endif /* !lint */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -412,20 +412,25 @@ puffs_null_node_fsync(struct puffs_usermount *pu, puffs_cookie_t opc,
|
||||||
int fd, rv;
|
int fd, rv;
|
||||||
int fflags;
|
int fflags;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
DIR *dirp;
|
||||||
|
|
||||||
rv = 0;
|
rv = 0;
|
||||||
if (stat(PNPATH(pn), &sb) == -1)
|
if (stat(PNPATH(pn), &sb) == -1)
|
||||||
return errno;
|
return errno;
|
||||||
if (S_ISDIR(sb.st_mode)) {
|
if (S_ISDIR(sb.st_mode)) {
|
||||||
DIR *dirp;
|
if ((dirp = opendir(PNPATH(pn))) == NULL)
|
||||||
if ((dirp = opendir(PNPATH(pn))) == 0)
|
|
||||||
return errno;
|
return errno;
|
||||||
fd = dirfd(dirp);
|
fd = dirfd(dirp);
|
||||||
if (fd == -1)
|
if (fd == -1) {
|
||||||
return errno;
|
rv = errno;
|
||||||
|
closedir(dirp);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
if (fsync(fd) == -1)
|
if (fsync(fd) == -1)
|
||||||
rv = errno;
|
rv = errno;
|
||||||
|
|
||||||
|
closedir(dirp);
|
||||||
} else {
|
} else {
|
||||||
fd = writeableopen(PNPATH(pn));
|
fd = writeableopen(PNPATH(pn));
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
|
@ -440,9 +445,9 @@ puffs_null_node_fsync(struct puffs_usermount *pu, puffs_cookie_t opc,
|
||||||
|
|
||||||
if (fsync_range(fd, fflags, offlo, offhi - offlo) == -1)
|
if (fsync_range(fd, fflags, offlo, offhi - offlo) == -1)
|
||||||
rv = errno;
|
rv = errno;
|
||||||
}
|
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue