diff mbox

hotkey: close fd on error

Message ID 1367878015-18122-1-git-send-email-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King May 6, 2013, 10:06 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Coverity CID #997348, Resource leak.

Need to close fd before we return.

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

Comments

Alex Hung May 7, 2013, 3:40 a.m. UTC | #1
On 05/07/2013 06:06 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997348, Resource leak.
>
> Need to close fd before we return.
>
> Signed-off-by: Colin Ian King <colin.king@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);
>
Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu May 10, 2013, 8:22 a.m. UTC | #2
On 05/07/2013 06:06 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997348, Resource leak.
>
> Need to close fd before we return.
>
> Signed-off-by: Colin Ian King <colin.king@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);
>
Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox

Patch

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);