[PATCH] hotkey: close fd on error

Colin King colin.king at canonical.com
Mon May 6 22:06:55 UTC 2013


From: Colin Ian King <colin.king at canonical.com>

Coverity CID #997348, Resource leak.

Need to close fd before we return.

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 src/hotkey/hotkey/hotkey.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/hotkey/hotkey/hotkey.c b/src/hotkey/hotkey/hotkey.c
index 38be7b0..ff3c669 100644
--- a/src/hotkey/hotkey/hotkey.c
+++ b/src/hotkey/hotkey/hotkey.c
@@ -84,6 +84,7 @@ static int hotkey_test(fwts_framework *fw, char *dev, fwts_list *hotkeys)
 
 	if (ioctl(fd, EVIOCGRAB, (void*)1)) {	/* Get focus */
 		fwts_log_error(fw, "Cannot grab device %s.", path);
+		close(fd);
 		return FWTS_ERROR;
 	}
 
@@ -106,6 +107,7 @@ static int hotkey_test(fwts_framework *fw, char *dev, fwts_list *hotkeys)
 
 	if (ioctl(fd, EVIOCGRAB, (void*)0)) {	/* Release */
 		fwts_log_error(fw, "Cannot un-grab device %s.", path);
+		close(fd);
 		return FWTS_ERROR;
 	}
 	close(fd);
-- 
1.8.1.2




More information about the fwts-devel mailing list