pam: do not leak file descriptor if flock fails

If flock fails, fd is not returned to caller so it cannot clean up.
This commit is contained in:
Andrey Borzenkov 2011-03-10 17:39:02 +03:00 committed by Lennart Poettering
parent 756a8d17bb
commit 90102b22ba

View File

@ -198,8 +198,12 @@ static int open_file_and_lock(const char *fn) {
* as the filesystems in question should be local, and only
* locally accessible, and most likely even tmpfs. */
if (flock(fd, LOCK_EX) < 0)
return -errno;
if (flock(fd, LOCK_EX) < 0) {
int r = -errno;
close_nointr_nofail(fd);
return r;
}
return fd;
}