libshare: nfs: don't leak nfs_lock_fd when lock fails
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: George Wilson <gwilson@delphix.com> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #11886
This commit is contained in:
parent
30620ad8e1
commit
501da8d433
|
@ -65,17 +65,22 @@ static int nfs_lock_fd = -1;
|
|||
static int
|
||||
nfs_exports_lock(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
nfs_lock_fd = open(ZFS_EXPORTS_LOCK,
|
||||
O_RDWR | O_CREAT, 0600);
|
||||
if (nfs_lock_fd == -1) {
|
||||
err = errno;
|
||||
fprintf(stderr, "failed to lock %s: %s\n",
|
||||
ZFS_EXPORTS_LOCK, strerror(errno));
|
||||
return (errno);
|
||||
ZFS_EXPORTS_LOCK, strerror(err));
|
||||
return (err);
|
||||
}
|
||||
if (flock(nfs_lock_fd, LOCK_EX) != 0) {
|
||||
err = errno;
|
||||
fprintf(stderr, "failed to lock %s: %s\n",
|
||||
ZFS_EXPORTS_LOCK, strerror(errno));
|
||||
return (errno);
|
||||
ZFS_EXPORTS_LOCK, strerror(err));
|
||||
(void) close(nfs_lock_fd);
|
||||
return (err);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -65,17 +65,22 @@ static int nfs_lock_fd = -1;
|
|||
static int
|
||||
nfs_exports_lock(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
nfs_lock_fd = open(ZFS_EXPORTS_LOCK,
|
||||
O_RDWR | O_CREAT, 0600);
|
||||
if (nfs_lock_fd == -1) {
|
||||
err = errno;
|
||||
fprintf(stderr, "failed to lock %s: %s\n",
|
||||
ZFS_EXPORTS_LOCK, strerror(errno));
|
||||
return (errno);
|
||||
ZFS_EXPORTS_LOCK, strerror(err));
|
||||
return (err);
|
||||
}
|
||||
if (flock(nfs_lock_fd, LOCK_EX) != 0) {
|
||||
err = errno;
|
||||
fprintf(stderr, "failed to lock %s: %s\n",
|
||||
ZFS_EXPORTS_LOCK, strerror(errno));
|
||||
return (errno);
|
||||
ZFS_EXPORTS_LOCK, strerror(err));
|
||||
(void) close(nfs_lock_fd);
|
||||
return (err);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue