util: fix close() call on wrong variable
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Wed, 5 Oct 2011 20:31:41 +0000 (22:31 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 10 Oct 2011 20:30:57 +0000 (22:30 +0200)
Detected by "cppcheck" (actually it detected a file descriptor leak)

src/util.c

index 7977ee4..e46606d 100644 (file)
@@ -2307,8 +2307,10 @@ int chvt(int vt) {
                         0
                 };
 
-                if (ioctl(fd, TIOCLINUX, tiocl) < 0)
-                        return -errno;
+                if (ioctl(fd, TIOCLINUX, tiocl) < 0) {
+                        r = -errno;
+                        goto fail;
+                }
 
                 vt = tiocl[0] <= 0 ? 1 : tiocl[0];
         }
@@ -2316,7 +2318,8 @@ int chvt(int vt) {
         if (ioctl(fd, VT_ACTIVATE, vt) < 0)
                 r = -errno;
 
-        close_nointr_nofail(r);
+fail:
+        close_nointr_nofail(fd);
         return r;
 }