chiark / gitweb /
pam: do not leak file descriptor if flock fails
[elogind.git] / src / pam-module.c
index 7f915847052b061dd0de370aad67b615dbf36532..e1a1a5001cedc9b438a31546906511949716c703 100644 (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;
 }