[systemd-devel] [PATCH 2/2] Fix close() call on wrong variable

Thomas Jarosch thomas.jarosch at intra2net.com
Wed Oct 5 13:31:41 PDT 2011


Detected by "cppcheck" (actually it detected a file descriptor leak)

Please CC: comments.

Signed-off-by: Thomas Jarosch <thomas.jarosch at intra2net.com>
---
 src/util.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/util.c b/src/util.c
index 7977ee4..ae9d9bd 100644
--- a/src/util.c
+++ b/src/util.c
@@ -2308,7 +2308,10 @@ int chvt(int vt) {
                 };
 
                 if (ioctl(fd, TIOCLINUX, tiocl) < 0)
-                        return -errno;
+                {
+                    r = -errno;
+                    goto fail;
+                }
 
                 vt = tiocl[0] <= 0 ? 1 : tiocl[0];
         }
@@ -2316,7 +2319,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;
 }
 
-- 
1.7.4.4



More information about the systemd-devel mailing list