Patchwork lib: fwts_framework: free resources on error

login
register
mail settings
Submitter Colin King
Date May 7, 2013, 6:53 a.m.
Message ID <1367909617-32193-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/242039/
State Accepted
Headers show

Comments

Colin King - May 7, 2013, 6:53 a.m.
From: Colin Ian King <colin.king@canonical.com>

Coverity CID#997345: Resource leak

We need to free args and fw on fwts_args_add_option() error
exit.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_framework.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Alex Hung - May 8, 2013, 2:02 a.m.
On 05/07/2013 02:53 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID#997345: Resource leak
>
> We need to free args and fw on fwts_args_add_option() error
> exit.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_framework.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
> index 57079e6..67dd3ab 100644
> --- a/src/lib/src/fwts_framework.c
> +++ b/src/lib/src/fwts_framework.c
> @@ -1195,7 +1195,7 @@ int fwts_framework_args(const int argc, char **argv)
>   	ret = fwts_args_add_options(fwts_framework_options,
>   		fwts_framework_options_handler, NULL);
>   	if (ret == FWTS_ERROR)
> -		return ret;
> +		goto tidy_args;
>
>   	fw->firmware_type = fwts_firmware_detect();
>
> @@ -1354,7 +1354,6 @@ tidy:
>   tidy_close:
>   	fwts_acpi_free_tables();
>   	fwts_summary_deinit();
> -	fwts_args_free();
>
>   	free(fw->lspci);
>   	free(fw->results_logname);
> @@ -1370,6 +1369,8 @@ tidy_close:
>   	if ((fw->total.failed > 0) || (fw->total.warning > 0))
>   		ret = FWTS_ERROR;
>
> +tidy_args:
> +	fwts_args_free();
>   	free(fw);
>
>   	return ret;
>
Acked-by: Alex Hung <alex.hung@canonical.com>
Keng-Yu Lin - May 20, 2013, 7:23 a.m.
On Tue, May 7, 2013 at 2:53 PM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID#997345: Resource leak
>
> We need to free args and fw on fwts_args_add_option() error
> exit.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_framework.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
> index 57079e6..67dd3ab 100644
> --- a/src/lib/src/fwts_framework.c
> +++ b/src/lib/src/fwts_framework.c
> @@ -1195,7 +1195,7 @@ int fwts_framework_args(const int argc, char **argv)
>         ret = fwts_args_add_options(fwts_framework_options,
>                 fwts_framework_options_handler, NULL);
>         if (ret == FWTS_ERROR)
> -               return ret;
> +               goto tidy_args;
>
>         fw->firmware_type = fwts_firmware_detect();
>
> @@ -1354,7 +1354,6 @@ tidy:
>  tidy_close:
>         fwts_acpi_free_tables();
>         fwts_summary_deinit();
> -       fwts_args_free();
>
>         free(fw->lspci);
>         free(fw->results_logname);
> @@ -1370,6 +1369,8 @@ tidy_close:
>         if ((fw->total.failed > 0) || (fw->total.warning > 0))
>                 ret = FWTS_ERROR;
>
> +tidy_args:
> +       fwts_args_free();
>         free(fw);
>
>         return ret;
> --
> 1.8.1.2
>

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

Patch

diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
index 57079e6..67dd3ab 100644
--- a/src/lib/src/fwts_framework.c
+++ b/src/lib/src/fwts_framework.c
@@ -1195,7 +1195,7 @@  int fwts_framework_args(const int argc, char **argv)
 	ret = fwts_args_add_options(fwts_framework_options,
 		fwts_framework_options_handler, NULL);
 	if (ret == FWTS_ERROR)
-		return ret;
+		goto tidy_args;
 
 	fw->firmware_type = fwts_firmware_detect();
 
@@ -1354,7 +1354,6 @@  tidy:
 tidy_close:
 	fwts_acpi_free_tables();
 	fwts_summary_deinit();
-	fwts_args_free();
 
 	free(fw->lspci);
 	free(fw->results_logname);
@@ -1370,6 +1369,8 @@  tidy_close:
 	if ((fw->total.failed > 0) || (fw->total.warning > 0))
 		ret = FWTS_ERROR;
 
+tidy_args:
+	fwts_args_free();
 	free(fw);
 
 	return ret;