diff mbox series

lib: fwts_log_json: fix memory leak

Message ID 20200824093057.63672-1-colin.king@canonical.com
State Accepted
Headers show
Series lib: fwts_log_json: fix memory leak | expand

Commit Message

Colin Ian King Aug. 24, 2020, 9:30 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

The string str is not being free'd after use, leading to a memory
leak. Free it.

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

Comments

Alex Hung Aug. 24, 2020, 4:14 p.m. UTC | #1
On 2020-08-24 3:30 a.m., Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The string str is not being free'd after use, leading to a memory
> leak. Free it.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_log_json.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/lib/src/fwts_log_json.c b/src/lib/src/fwts_log_json.c
> index 1a917e63..7bb5110a 100644
> --- a/src/lib/src/fwts_log_json.c
> +++ b/src/lib/src/fwts_log_json.c
> @@ -211,7 +211,7 @@ static void fwts_log_open_json(fwts_log_file *log_file)
>  
>  static void fwts_log_close_json(fwts_log_file *log_file)
>  {
> -	const char *str;
> +	char *str;
>  
>  	fwts_log_section_end_json(log_file);
>  
> @@ -233,6 +233,7 @@ static void fwts_log_close_json(fwts_log_file *log_file)
>  		log_file->line_number++;
>  	}
>  	json_object_put(json_stack[0].obj);
> +	free(str);
>  }
>  
>  fwts_log_ops fwts_log_json_ops = {
> 


Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu Aug. 25, 2020, 2:34 a.m. UTC | #2
On 8/24/20 5:30 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The string str is not being free'd after use, leading to a memory
> leak. Free it.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_log_json.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/lib/src/fwts_log_json.c b/src/lib/src/fwts_log_json.c
> index 1a917e63..7bb5110a 100644
> --- a/src/lib/src/fwts_log_json.c
> +++ b/src/lib/src/fwts_log_json.c
> @@ -211,7 +211,7 @@ static void fwts_log_open_json(fwts_log_file *log_file)
>  
>  static void fwts_log_close_json(fwts_log_file *log_file)
>  {
> -	const char *str;
> +	char *str;
>  
>  	fwts_log_section_end_json(log_file);
>  
> @@ -233,6 +233,7 @@ static void fwts_log_close_json(fwts_log_file *log_file)
>  		log_file->line_number++;
>  	}
>  	json_object_put(json_stack[0].obj);
> +	free(str);
>  }
>  
>  fwts_log_ops fwts_log_json_ops = {
> 


Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox series

Patch

diff --git a/src/lib/src/fwts_log_json.c b/src/lib/src/fwts_log_json.c
index 1a917e63..7bb5110a 100644
--- a/src/lib/src/fwts_log_json.c
+++ b/src/lib/src/fwts_log_json.c
@@ -211,7 +211,7 @@  static void fwts_log_open_json(fwts_log_file *log_file)
 
 static void fwts_log_close_json(fwts_log_file *log_file)
 {
-	const char *str;
+	char *str;
 
 	fwts_log_section_end_json(log_file);
 
@@ -233,6 +233,7 @@  static void fwts_log_close_json(fwts_log_file *log_file)
 		log_file->line_number++;
 	}
 	json_object_put(json_stack[0].obj);
+	free(str);
 }
 
 fwts_log_ops fwts_log_json_ops = {