diff mbox series

[03/12] zap_sector: fix memory leak

Message ID 8ea5c607-54cc-ccaf-3e4b-ee2af0160a0b@huawei.com
State Superseded
Headers show
Series e2fsprogs: some bugfixs and some code cleanups | expand

Commit Message

wuguanghao May 24, 2021, 11:20 a.m. UTC
In zap_sector(), need free buf before return,
otherwise it will cause memory leak.

Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Reviewed-by: Wu Bo <wubo40@huawei.com>
---
 misc/mke2fs.c | 1 +
 1 file changed, 1 insertion(+)

--

Comments

Artem Blagodarenko May 24, 2021, 2:40 p.m. UTC | #1
Hello Wu,

Thank you for the fixes.

It looks like free and return operators should be placed in {} block.

{
	free(buf);
 	return;
}

Now function returns any time block is read successfully.

Also, this patch can not be applied cleanly to the master HEAD because of wrong offsets. Please rebase.

Best regards,
Artem Blagodarenko.

> On 24 May 2021, at 14:20, Wu Guanghao <wuguanghao3@huawei.com> wrote:
> 
> In zap_sector(), need free buf before return,
> otherwise it will cause memory leak.
> 
> Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
> Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
> Reviewed-by: Wu Bo <wubo40@huawei.com>
> ---
> misc/mke2fs.c | 1 +
> 1 file changed, 1 insertion(+)
> 
> diff --git a/misc/mke2fs.c b/misc/mke2fs.c
> index afbcf486..94f81da9 100644
> --- a/misc/mke2fs.c
> +++ b/misc/mke2fs.c
> @@ -586,6 +586,7 @@ static void zap_sector(ext2_filsys fs, int sect, int nsect)
> 			magic = (unsigned int *) (buf + BSD_LABEL_OFFSET);
> 			if ((*magic == BSD_DISKMAGIC) ||
> 				(*magic == BSD_MAGICDISK))
> +				free(buf);
> 				return;
> 		}
> 	}
> --
wuguanghao May 25, 2021, 2:16 a.m. UTC | #2
Thank you for your comments, I will modify it in the v2 version.

Best regards
Wu Guanghao

在 2021/5/24 22:40, Благодаренко Артём 写道:
> Hello Wu,
> 
> Thank you for the fixes.
> 
> It looks like free and return operators should be placed in {} block.
> 
> {
> 	free(buf);
>  	return;
> }
> 
> Now function returns any time block is read successfully.
> 
> Also, this patch can not be applied cleanly to the master HEAD because of wrong offsets. Please rebase.
> 
> Best regards,
> Artem Blagodarenko.
> 
>> On 24 May 2021, at 14:20, Wu Guanghao <wuguanghao3@huawei.com> wrote:
>>
>> In zap_sector(), need free buf before return,
>> otherwise it will cause memory leak.
>>
>> Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
>> Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
>> Reviewed-by: Wu Bo <wubo40@huawei.com>
>> ---
>> misc/mke2fs.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/misc/mke2fs.c b/misc/mke2fs.c
>> index afbcf486..94f81da9 100644
>> --- a/misc/mke2fs.c
>> +++ b/misc/mke2fs.c
>> @@ -586,6 +586,7 @@ static void zap_sector(ext2_filsys fs, int sect, int nsect)
>> 			magic = (unsigned int *) (buf + BSD_LABEL_OFFSET);
>> 			if ((*magic == BSD_DISKMAGIC) ||
>> 				(*magic == BSD_MAGICDISK))
>> +				free(buf);
>> 				return;
>> 		}
>> 	}
>> -- 
> 
> .
>
diff mbox series

Patch

diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index afbcf486..94f81da9 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -586,6 +586,7 @@  static void zap_sector(ext2_filsys fs, int sect, int nsect)
 			magic = (unsigned int *) (buf + BSD_LABEL_OFFSET);
 			if ((*magic == BSD_DISKMAGIC) ||
 				(*magic == BSD_MAGICDISK))
+				free(buf);
 				return;
 		}
 	}