chiark / gitweb /
pam: do not leak file descriptor if flock fails
authorAndrey Borzenkov <arvidjaar@gmail.com>
Thu, 10 Mar 2011 14:39:02 +0000 (17:39 +0300)
committerLennart Poettering <lennart@poettering.net>
Thu, 10 Mar 2011 19:48:58 +0000 (20:48 +0100)
If flock fails, fd is not returned to caller so it cannot clean up.

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;
 }