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: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=90102b22ba0a9a6aa8ff1b9d32349e100902a8d7;p=systemd 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 7f915847..e1a1a500 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; }