diff mbox

acpi: battery: free gpe resources on error

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

Commit Message

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

Coverity CID #997269, Resource leak.

Need to free gpe resources before we return.

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

Comments

Alex Hung May 7, 2013, 5:38 a.m. UTC | #1
On 05/07/2013 06:30 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997269, Resource leak.
>
> Need to free gpe resources before we return.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/acpi/battery/battery.c | 3 +++
>   1 file changed, 3 insertions(+)
>
> diff --git a/src/acpi/battery/battery.c b/src/acpi/battery/battery.c
> index 2fbc228..f83f086 100644
> --- a/src/acpi/battery/battery.c
> +++ b/src/acpi/battery/battery.c
> @@ -80,6 +80,7 @@ static int wait_for_acpi_event(fwts_framework *fw, char *name)
>
>   	if ((fd = fwts_acpi_event_open()) < 0) {
>   		fwts_log_error(fw, "Cannot connect to acpid.");
> +		fwts_gpe_free(gpes_start, gpe_count);
>   		return FWTS_ERROR;
>   	}
>
> @@ -102,6 +103,8 @@ static int wait_for_acpi_event(fwts_framework *fw, char *name)
>
>   	if ((gpe_count = fwts_gpe_read(&gpes_end)) == FWTS_ERROR) {
>   		fwts_log_error(fw, "Cannot read GPEs.");
> +		fwts_gpe_free(gpes_start, gpe_count);
> +		return FWTS_ERROR;
>   	}
>
>   	fwts_gpe_test(fw, gpes_start, gpes_end, gpe_count);
>
Acked-by: Alex Hung <alex.hung@canonical.com>
Colin Ian King May 20, 2013, 10:17 a.m. UTC | #2
On 06/05/13 23:30, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Coverity CID #997269, Resource leak.
> 
> Need to free gpe resources before we return.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/acpi/battery/battery.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/src/acpi/battery/battery.c b/src/acpi/battery/battery.c
> index 2fbc228..f83f086 100644
> --- a/src/acpi/battery/battery.c
> +++ b/src/acpi/battery/battery.c
> @@ -80,6 +80,7 @@ static int wait_for_acpi_event(fwts_framework *fw, char *name)
>  
>  	if ((fd = fwts_acpi_event_open()) < 0) {
>  		fwts_log_error(fw, "Cannot connect to acpid.");
> +		fwts_gpe_free(gpes_start, gpe_count);
>  		return FWTS_ERROR;
>  	}
>  
> @@ -102,6 +103,8 @@ static int wait_for_acpi_event(fwts_framework *fw, char *name)
>  
>  	if ((gpe_count = fwts_gpe_read(&gpes_end)) == FWTS_ERROR) {
>  		fwts_log_error(fw, "Cannot read GPEs.");
> +		fwts_gpe_free(gpes_start, gpe_count);
> +		return FWTS_ERROR;
>  	}
>  
>  	fwts_gpe_test(fw, gpes_start, gpes_end, gpe_count);
> 

we require one more ack on this, and for some reason I don't see it on
patchworks so it's not showing up.

Colin
Keng-Yu Lin May 20, 2013, 5:51 p.m. UTC | #3
On Tue, May 7, 2013 at 6:30 AM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997269, Resource leak.
>
> Need to free gpe resources before we return.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/acpi/battery/battery.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/src/acpi/battery/battery.c b/src/acpi/battery/battery.c
> index 2fbc228..f83f086 100644
> --- a/src/acpi/battery/battery.c
> +++ b/src/acpi/battery/battery.c
> @@ -80,6 +80,7 @@ static int wait_for_acpi_event(fwts_framework *fw, char *name)
>
>         if ((fd = fwts_acpi_event_open()) < 0) {
>                 fwts_log_error(fw, "Cannot connect to acpid.");
> +               fwts_gpe_free(gpes_start, gpe_count);
>                 return FWTS_ERROR;
>         }
>
> @@ -102,6 +103,8 @@ static int wait_for_acpi_event(fwts_framework *fw, char *name)
>
>         if ((gpe_count = fwts_gpe_read(&gpes_end)) == FWTS_ERROR) {
>                 fwts_log_error(fw, "Cannot read GPEs.");
> +               fwts_gpe_free(gpes_start, gpe_count);
> +               return FWTS_ERROR;
>         }
>
>         fwts_gpe_test(fw, gpes_start, gpes_end, gpe_count);
> --
> 1.8.1.2
>

Acked-by: Keng-Yu Lin <kengyu@canonical.com>
diff mbox

Patch

diff --git a/src/acpi/battery/battery.c b/src/acpi/battery/battery.c
index 2fbc228..f83f086 100644
--- a/src/acpi/battery/battery.c
+++ b/src/acpi/battery/battery.c
@@ -80,6 +80,7 @@  static int wait_for_acpi_event(fwts_framework *fw, char *name)
 
 	if ((fd = fwts_acpi_event_open()) < 0) {
 		fwts_log_error(fw, "Cannot connect to acpid.");
+		fwts_gpe_free(gpes_start, gpe_count);
 		return FWTS_ERROR;
 	}
 
@@ -102,6 +103,8 @@  static int wait_for_acpi_event(fwts_framework *fw, char *name)
 
 	if ((gpe_count = fwts_gpe_read(&gpes_end)) == FWTS_ERROR) {
 		fwts_log_error(fw, "Cannot read GPEs.");
+		fwts_gpe_free(gpes_start, gpe_count);
+		return FWTS_ERROR;
 	}
 
 	fwts_gpe_test(fw, gpes_start, gpes_end, gpe_count);