Patchwork lib: fwts_args: free long_options on error

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

Comments

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

Coverity CID#997347: Resource leak

We need to free long_options on the error path too.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_args.c | 2 ++
 1 file changed, 2 insertions(+)
Alex Hung - May 8, 2013, 1:57 a.m.
On 05/07/2013 02:43 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID#997347: Resource leak
>
> We need to free long_options on the error path too.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_args.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/src/lib/src/fwts_args.c b/src/lib/src/fwts_args.c
> index 05c4c00..483fa30 100644
> --- a/src/lib/src/fwts_args.c
> +++ b/src/lib/src/fwts_args.c
> @@ -132,6 +132,7 @@ int fwts_args_parse(fwts_framework *fw, const int argc, char * const argv[])
>   					short_options = realloc(short_options,
>   						short_options_len + len + 1);
>   					if (short_options == NULL) {
> +						free(long_options);
>   						fwts_log_error(fw,
>   							"Out of memory "
>   							"allocating options.");
> @@ -142,6 +143,7 @@ int fwts_args_parse(fwts_framework *fw, const int argc, char * const argv[])
>   				} else {
>   					short_options = calloc(1, len + 1);
>   					if (short_options == NULL) {
> +						free(long_options);
>   						fwts_log_error(fw,
>   							"Out of memory "
>   							"allocating options.");
>
Acked-by: Alex Hung <alex.hung@canonical.com>
Keng-Yu Lin - May 20, 2013, 7:22 a.m.
On Tue, May 7, 2013 at 2:43 PM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID#997347: Resource leak
>
> We need to free long_options on the error path too.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_args.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/src/lib/src/fwts_args.c b/src/lib/src/fwts_args.c
> index 05c4c00..483fa30 100644
> --- a/src/lib/src/fwts_args.c
> +++ b/src/lib/src/fwts_args.c
> @@ -132,6 +132,7 @@ int fwts_args_parse(fwts_framework *fw, const int argc, char * const argv[])
>                                         short_options = realloc(short_options,
>                                                 short_options_len + len + 1);
>                                         if (short_options == NULL) {
> +                                               free(long_options);
>                                                 fwts_log_error(fw,
>                                                         "Out of memory "
>                                                         "allocating options.");
> @@ -142,6 +143,7 @@ int fwts_args_parse(fwts_framework *fw, const int argc, char * const argv[])
>                                 } else {
>                                         short_options = calloc(1, len + 1);
>                                         if (short_options == NULL) {
> +                                               free(long_options);
>                                                 fwts_log_error(fw,
>                                                         "Out of memory "
>                                                         "allocating options.");
> --
> 1.8.1.2
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>

Patch

diff --git a/src/lib/src/fwts_args.c b/src/lib/src/fwts_args.c
index 05c4c00..483fa30 100644
--- a/src/lib/src/fwts_args.c
+++ b/src/lib/src/fwts_args.c
@@ -132,6 +132,7 @@  int fwts_args_parse(fwts_framework *fw, const int argc, char * const argv[])
 					short_options = realloc(short_options,
 						short_options_len + len + 1);
 					if (short_options == NULL) {
+						free(long_options);
 						fwts_log_error(fw,
 							"Out of memory "
 							"allocating options.");
@@ -142,6 +143,7 @@  int fwts_args_parse(fwts_framework *fw, const int argc, char * const argv[])
 				} else {
 					short_options = calloc(1, len + 1);
 					if (short_options == NULL) {
+						free(long_options);
 						fwts_log_error(fw,
 							"Out of memory "
 							"allocating options.");