* [PATCH] dt-ops: fix memory leak when new_node malloc fails
@ 2020-11-30 6:41 qiuguorui1
2020-11-30 16:39 ` Simon Horman
0 siblings, 1 reply; 3+ messages in thread
From: qiuguorui1 @ 2020-11-30 6:41 UTC (permalink / raw)
To: kexec, bhsharma; +Cc: qiuguorui1, horms, leeyou.li, zengweilin
In function dtb_set_property, when malloc new_node fails,
we need to free new_dtb before return.
Fixes: f56cbcf4c2766 ("kexec/dt-ops.c: Fix '/chosen' v/s 'chosen' node
being passed to fdt helper functions")
Signed-off-by: qiuguorui1 <qiuguorui1@huawei.com>
---
kexec/dt-ops.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/kexec/dt-ops.c b/kexec/dt-ops.c
index dd2feaa..cc5feae 100644
--- a/kexec/dt-ops.c
+++ b/kexec/dt-ops.c
@@ -89,6 +89,7 @@ int dtb_set_property(char **dtb, off_t *dtb_size, const char *node,
new_node = malloc(strlen("/") + strlen(node) + 1);
if (!new_node) {
dbgprintf("%s: malloc failed\n", __func__);
+ free(new_dtb);
return -ENOMEM;
}
--
2.12.3
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] dt-ops: fix memory leak when new_node malloc fails
2020-11-30 6:41 [PATCH] dt-ops: fix memory leak when new_node malloc fails qiuguorui1
@ 2020-11-30 16:39 ` Simon Horman
0 siblings, 0 replies; 3+ messages in thread
From: Simon Horman @ 2020-11-30 16:39 UTC (permalink / raw)
To: qiuguorui1; +Cc: leeyou.li, bhsharma, kexec, zengweilin
On Mon, Nov 30, 2020 at 02:41:56PM +0800, qiuguorui1 wrote:
> In function dtb_set_property, when malloc new_node fails,
> we need to free new_dtb before return.
>
> Fixes: f56cbcf4c2766 ("kexec/dt-ops.c: Fix '/chosen' v/s 'chosen' node
> being passed to fdt helper functions")
> Signed-off-by: qiuguorui1 <qiuguorui1@huawei.com>
> ---
> kexec/dt-ops.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/kexec/dt-ops.c b/kexec/dt-ops.c
> index dd2feaa..cc5feae 100644
> --- a/kexec/dt-ops.c
> +++ b/kexec/dt-ops.c
> @@ -89,6 +89,7 @@ int dtb_set_property(char **dtb, off_t *dtb_size, const char *node,
> new_node = malloc(strlen("/") + strlen(node) + 1);
> if (!new_node) {
> dbgprintf("%s: malloc failed\n", __func__);
> + free(new_dtb);
Can we use the goto idiom here,
as is used elsewhere in this function?
> return -ENOMEM;
> }
>
> --
> 2.12.3
>
>
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec
>
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] dt-ops: fix memory leak when new_node malloc fails
@ 2020-12-01 3:11 qiuguorui
0 siblings, 0 replies; 3+ messages in thread
From: qiuguorui @ 2020-12-01 3:11 UTC (permalink / raw)
To: Simon Horman
Cc: Liyou (leeyou, RTOS), bhsharma@redhat.com,
kexec@lists.infradead.org, Zengweilin
On 2020/12/1 00:39, Simon Horman wrote:
>On Mon, Nov 30, 2020 at 02:41:56PM +0800, qiuguorui1 wrote:
>> In function dtb_set_property, when malloc new_node fails,
>> we need to free new_dtb before return.
>>
>> Fixes: f56cbcf4c2766 ("kexec/dt-ops.c: Fix '/chosen' v/s 'chosen' node
>> being passed to fdt helper functions")
>> Signed-off-by: qiuguorui1 <qiuguorui1@huawei.com>
>> ---
>> kexec/dt-ops.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/kexec/dt-ops.c b/kexec/dt-ops.c
>> index dd2feaa..cc5feae 100644
>> --- a/kexec/dt-ops.c
>> +++ b/kexec/dt-ops.c
>> @@ -89,6 +89,7 @@ int dtb_set_property(char **dtb, off_t *dtb_size, const char *node,
>> new_node = malloc(strlen("/") + strlen(node) + 1);
>> if (!new_node) {
>> dbgprintf("%s: malloc failed\n", __func__);
>> + free(new_dtb);
>
>Can we use the goto idiom here,
>as is used elsewhere in this function?
Sure! Thanks for your advice,I will send a v2 patch soon.
>> return -ENOMEM;
>> }
>>
>> --
>> 2.12.3
-----邮件原件-----
发件人: Simon Horman [mailto:horms@verge.net.au]
发送时间: 2020年12月1日 0:39
收件人: qiuguorui <qiuguorui1@huawei.com>
抄送: kexec@lists.infradead.org; bhsharma@redhat.com; Liyou (leeyou, RTOS) <leeyou.li@huawei.com>; Zengweilin <zengweilin@huawei.com>
主题: Re: [PATCH] dt-ops: fix memory leak when new_node malloc fails
On Mon, Nov 30, 2020 at 02:41:56PM +0800, qiuguorui1 wrote:
> In function dtb_set_property, when malloc new_node fails,
> we need to free new_dtb before return.
>
> Fixes: f56cbcf4c2766 ("kexec/dt-ops.c: Fix '/chosen' v/s 'chosen' node
> being passed to fdt helper functions")
> Signed-off-by: qiuguorui1 <qiuguorui1@huawei.com>
> ---
> kexec/dt-ops.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/kexec/dt-ops.c b/kexec/dt-ops.c
> index dd2feaa..cc5feae 100644
> --- a/kexec/dt-ops.c
> +++ b/kexec/dt-ops.c
> @@ -89,6 +89,7 @@ int dtb_set_property(char **dtb, off_t *dtb_size, const char *node,
> new_node = malloc(strlen("/") + strlen(node) + 1);
> if (!new_node) {
> dbgprintf("%s: malloc failed\n", __func__);
> + free(new_dtb);
Can we use the goto idiom here,
as is used elsewhere in this function?
> return -ENOMEM;
> }
>
> --
> 2.12.3
>
>
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec
>
_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-12-01 3:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-30 6:41 [PATCH] dt-ops: fix memory leak when new_node malloc fails qiuguorui1
2020-11-30 16:39 ` Simon Horman
-- strict thread matches above, loose matches on Subject: below --
2020-12-01 3:11 qiuguorui
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox