]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login: remove file descriptor leak [cppcheck]
authorSami Kerola <kerolasa@iki.fi>
Wed, 20 Feb 2013 21:31:09 +0000 (21:31 +0000)
committerKarel Zak <kzak@redhat.com>
Mon, 4 Mar 2013 11:28:34 +0000 (12:28 +0100)
[login-utils/login.c:510]: (error) Resource leak: fd

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
login-utils/login.c

index a17083b5f8b30c3377bccddc514fc11eef3fa661..425053406a088964c865592adc4418cc19896a17 100644 (file)
@@ -506,8 +506,10 @@ static void log_lastlog(struct login_context *cxt)
        if (fd < 0)
                return;
 
-       if (lseek(fd, (off_t) cxt->pwd->pw_uid * sizeof(ll), SEEK_SET) == -1)
+       if (lseek(fd, (off_t) cxt->pwd->pw_uid * sizeof(ll), SEEK_SET) == -1) {
+               close(fd);
                return;
+       }
 
        /*
         * Print last log message