Patchwork hotkey: close fd on error

login
register
mail settings
Submitter Colin King
Date May 6, 2013, 10:06 p.m.
Message ID <1367878015-18122-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/241802/
State Accepted
Headers show

Comments

Colin King - May 6, 2013, 10:06 p.m.
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(+)
Alex Hung - May 7, 2013, 3:40 a.m.
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.
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>

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