Patchwork lib: fwts_log: free log_file on error exit

login
register
mail settings
Submitter Colin King
Date May 7, 2013, 7:03 a.m.
Message ID <1367910228-32752-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/242042/
State Rejected
Headers show

Comments

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

overity 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 | 1 +
 1 file changed, 1 insertion(+)
Alex Hung - May 8, 2013, 2:10 a.m.
On 05/07/2013 03:03 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> overity 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 | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/src/lib/src/fwts_log.c b/src/lib/src/fwts_log.c
> index 4667a76..41214da 100644
> --- a/src/lib/src/fwts_log.c
> +++ b/src/lib/src/fwts_log.c
> @@ -674,6 +674,7 @@ fwts_log *fwts_log_open(
>
>   				if (log_file->fp == NULL) {
>   					fwts_log_close(newlog);
> +					free(log_file);
>   					return NULL;
>   				}
>   			}
>

The patch looks good. Is it also needed to free(log_file) in the below 
if-statement just a little above?

if ((newname = fwts_log_filename(filename, mask)) == NULL) {
     fwts_log_close(newlog);
     return NULL;
}
Colin King - May 8, 2013, 6:43 a.m.
On 08/05/13 03:10, Alex Hung wrote:
> On 05/07/2013 03:03 PM, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> overity 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 | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/src/lib/src/fwts_log.c b/src/lib/src/fwts_log.c
>> index 4667a76..41214da 100644
>> --- a/src/lib/src/fwts_log.c
>> +++ b/src/lib/src/fwts_log.c
>> @@ -674,6 +674,7 @@ fwts_log *fwts_log_open(
>>
>>                   if (log_file->fp == NULL) {
>>                       fwts_log_close(newlog);
>> +                    free(log_file);
>>                       return NULL;
>>                   }
>>               }
>>
> 
> The patch looks good. Is it also needed to free(log_file) in the below
> if-statement just a little above?
> 
> if ((newname = fwts_log_filename(filename, mask)) == NULL) {
>     fwts_log_close(newlog);
>     return NULL;
> }
> 
> 
Well spotted. I will submit version 2 of the patch including this. Thanks.

Patch

diff --git a/src/lib/src/fwts_log.c b/src/lib/src/fwts_log.c
index 4667a76..41214da 100644
--- a/src/lib/src/fwts_log.c
+++ b/src/lib/src/fwts_log.c
@@ -674,6 +674,7 @@  fwts_log *fwts_log_open(
 
 				if (log_file->fp == NULL) {
 					fwts_log_close(newlog);
+					free(log_file);
 					return NULL;
 				}
 			}