From 90102b22ba0a9a6aa8ff1b9d32349e100902a8d7 Mon Sep 17 00:00:00 2001 From: Andrey Borzenkov Date: Thu, 10 Mar 2011 17:39:02 +0300 Subject: [PATCH] pam: do not leak file descriptor if flock fails If flock fails, fd is not returned to caller so it cannot clean up. --- src/pam-module.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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; } -- 2.30.2