[systemd-devel] [PATCH] pam: do not leak file descriptor if flock fails

Andrey Borzenkov arvidjaar at gmail.com
Thu Mar 10 06:39:02 PST 2011


If flock fails, fd is not returned to caller so it cannot clean up.

---
 src/pam-module.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/pam-module.c b/src/pam-module.c
index 7f91584..e1a1a50 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;
 }
-- 
tg: (fe783b0..) upstream/pam-flock-fd (depends on: origin/master)


More information about the systemd-devel mailing list