Patchwork [V2] lib: fwts_log: free log_file on error exit

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

Comments

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

Coverity CID#997342: Resource leak

log_file needs to be free'd on log_file->fp == NULL error
condition.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_log.c | 2 ++
 1 file changed, 2 insertions(+)
Alex Hung - May 8, 2013, 8:15 a.m.
On 05/08/2013 02:55 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID#997342: Resource leak
>
> log_file needs to be free'd on log_file->fp == NULL error
> condition.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_log.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/src/lib/src/fwts_log.c b/src/lib/src/fwts_log.c
> index 4667a76..b4a36ec 100644
> --- a/src/lib/src/fwts_log.c
> +++ b/src/lib/src/fwts_log.c
> @@ -667,6 +667,7 @@ fwts_log *fwts_log_open(
>   			case LOG_FILENAME_TYPE_FILE:
>   				if ((newname = fwts_log_filename(filename, mask)) == NULL) {
>   					fwts_log_close(newlog);
> +					free(log_file);
>   					return NULL;
>   				}
>   				log_file->fp = fopen(newname, mode);
> @@ -674,6 +675,7 @@ fwts_log *fwts_log_open(
>
>   				if (log_file->fp == NULL) {
>   					fwts_log_close(newlog);
> +					free(log_file);
>   					return NULL;
>   				}
>   			}
>
Acked-by: Alex Hung <alex.hung@canonical.com>
Keng-Yu Lin - May 20, 2013, 7:55 a.m.
On Wed, May 8, 2013 at 4:15 PM, Alex Hung <alex.hung@canonical.com> wrote:
> On 05/08/2013 02:55 PM, Colin King wrote:
>>
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> Coverity CID#997342: Resource leak
>>
>> log_file needs to be free'd on log_file->fp == NULL error
>> condition.
>>
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
>> ---
>>   src/lib/src/fwts_log.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/src/lib/src/fwts_log.c b/src/lib/src/fwts_log.c
>> index 4667a76..b4a36ec 100644
>> --- a/src/lib/src/fwts_log.c
>> +++ b/src/lib/src/fwts_log.c
>> @@ -667,6 +667,7 @@ fwts_log *fwts_log_open(
>>                         case LOG_FILENAME_TYPE_FILE:
>>                                 if ((newname = fwts_log_filename(filename,
>> mask)) == NULL) {
>>                                         fwts_log_close(newlog);
>> +                                       free(log_file);
>>                                         return NULL;
>>                                 }
>>                                 log_file->fp = fopen(newname, mode);
>> @@ -674,6 +675,7 @@ fwts_log *fwts_log_open(
>>
>>                                 if (log_file->fp == NULL) {
>>                                         fwts_log_close(newlog);
>> +                                       free(log_file);
>>                                         return NULL;
>>                                 }
>>                         }
>>
> Acked-by: Alex Hung <alex.hung@canonical.com>
>

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

Patch

diff --git a/src/lib/src/fwts_log.c b/src/lib/src/fwts_log.c
index 4667a76..b4a36ec 100644
--- a/src/lib/src/fwts_log.c
+++ b/src/lib/src/fwts_log.c
@@ -667,6 +667,7 @@  fwts_log *fwts_log_open(
 			case LOG_FILENAME_TYPE_FILE:
 				if ((newname = fwts_log_filename(filename, mask)) == NULL) {
 					fwts_log_close(newlog);
+					free(log_file);
 					return NULL;
 				}
 				log_file->fp = fopen(newname, mode);
@@ -674,6 +675,7 @@  fwts_log *fwts_log_open(
 
 				if (log_file->fp == NULL) {
 					fwts_log_close(newlog);
+					free(log_file);
 					return NULL;
 				}
 			}