[PATCH] erofs-utils: fix memory leak when load compress hints file

Huang Jianan huangjianan at oppo.com
Wed Feb 23 18:19:22 AEDT 2022


在 2022/2/18 15:02, Gao Xiang 写道:
> On Fri, Feb 18, 2022 at 11:11:36AM +0800, Huang Jianan via Linux-erofs wrote:
>> Execute fclose before return error.
>>
>> Signed-off-by: Huang Jianan <huangjianan at oppo.com>
> It's actually a file descriptor leakage?
>
> Thanks,
> Gao Xiang

Yes, I will fix this in the next version.

Thanks,
Jianan

>> ---
>>   lib/compress_hints.c | 10 +++++++---
>>   1 file changed, 7 insertions(+), 3 deletions(-)
>>
>> diff --git a/lib/compress_hints.c b/lib/compress_hints.c
>> index c3f3d48..c52e2d3 100644
>> --- a/lib/compress_hints.c
>> +++ b/lib/compress_hints.c
>> @@ -88,6 +88,7 @@ int erofs_load_compress_hints(void)
>>   	char buf[PATH_MAX + 100];
>>   	FILE *f;
>>   	unsigned int line, max_pclustersize = 0;
>> +	int ret = 0;
>>   
>>   	if (!cfg.c_compress_hints_file)
>>   		return 0;
>> @@ -105,7 +106,8 @@ int erofs_load_compress_hints(void)
>>   		if (!pattern || *pattern == '\0') {
>>   			erofs_err("cannot find a match pattern at line %u",
>>   				  line);
>> -			return -EINVAL;
>> +			ret = -EINVAL;
>> +			goto out;
>>   		}
>>   		if (pclustersize % EROFS_BLKSIZ) {
>>   			erofs_warn("invalid physical clustersize %u, "
>> @@ -119,10 +121,12 @@ int erofs_load_compress_hints(void)
>>   		if (pclustersize > max_pclustersize)
>>   			max_pclustersize = pclustersize;
>>   	}
>> -	fclose(f);
>> +
>>   	if (cfg.c_pclusterblks_max * EROFS_BLKSIZ < max_pclustersize) {
>>   		cfg.c_pclusterblks_max = max_pclustersize / EROFS_BLKSIZ;
>>   		erofs_warn("update max pclusterblks to %u", cfg.c_pclusterblks_max);
>>   	}
>> -	return 0;
>> +out:
>> +	fclose(f);
>> +	return ret;
>>   }
>> -- 
>> 2.25.1



More information about the Linux-erofs mailing list