mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-11-17 01:51:00 +03:00
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
fef8bd41fc
commit
0f4d83117a
@ -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 | O_CLOEXEC, 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 | O_CLOEXEC, 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
Block a user