From 678abaf91e2308f02fb679c2dc2679a3b6a5b8be Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Wed, 5 Oct 2011 22:31:41 +0200 Subject: [PATCH] util: fix close() call on wrong variable Detected by "cppcheck" (actually it detected a file descriptor leak) --- src/util.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/util.c b/src/util.c index 7977ee46..e46606da 100644 --- a/src/util.c +++ b/src/util.c @@ -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; } -- 2.39.5