From: Andrey Borzenkov Date: Thu, 10 Mar 2011 14:39:02 +0000 (+0300) Subject: pam: do not leak file descriptor if flock fails X-Git-Tag: v21~122 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=90102b22ba0a9a6aa8ff1b9d32349e100902a8d7;ds=inline pam: do not leak file descriptor if flock fails If flock fails, fd is not returned to caller so it cannot clean up. --- diff --git a/src/pam-module.c b/src/pam-module.c index 7f9158470..e1a1a5001 100644 --- a/src/pam-module.c +++ b/src/pam-module.c @@ -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; }