]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login: close() only a file descriptor that is open [coverity scan]
authorSami Kerola <kerolasa@iki.fi>
Sun, 9 Aug 2020 12:34:00 +0000 (13:34 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 16 Oct 2020 09:59:16 +0000 (11:59 +0200)
CID: 360819
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
login-utils/login.c

index e2eb108024e1ea627b6b3a04a0c2802040de4a84..37a52f6612f89208e83031718d70ee66669c0fab 100644 (file)
@@ -395,9 +395,10 @@ static void motd(void)
 #endif
                if (S_ISREG(st.st_mode) && st.st_size > 0) {
                        int fd = open(file, O_RDONLY, 0);
-                       if (fd >= 0)
+                       if (fd >= 0) {
                                sendfile(fileno(stdout), fd, NULL, st.st_size);
-                       close(fd);
+                               close(fd);
+                       }
                        done++;
                }
                if (firstonly && done)