All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] dt-ops: fix memory leak when new_node malloc fails
@ 2020-12-01  4:06 qiuguorui1
  2020-12-09 12:43 ` Simon Horman
  0 siblings, 1 reply; 2+ messages in thread
From: qiuguorui1 @ 2020-12-01  4:06 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>

v2:
  use goto instead of free here,based on Simon Horman's advice:
  "Can we use the goto idiom here, as is used elsewhere in this function?"

v1: http://lists.infradead.org/pipermail/kexec/2020-November/021809.html
---
 kexec/dt-ops.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kexec/dt-ops.c b/kexec/dt-ops.c
index dd2feaa..0a96b75 100644
--- a/kexec/dt-ops.c
+++ b/kexec/dt-ops.c
@@ -89,7 +89,8 @@ 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__);
-		return -ENOMEM;
+		result = -ENOMEM;
+		goto on_error;
 	}
 
 	strcpy(new_node, "/");
-- 
2.12.3


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] dt-ops: fix memory leak when new_node malloc fails
  2020-12-01  4:06 [PATCH v2] dt-ops: fix memory leak when new_node malloc fails qiuguorui1
@ 2020-12-09 12:43 ` Simon Horman
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Horman @ 2020-12-09 12:43 UTC (permalink / raw)
  To: qiuguorui1; +Cc: leeyou.li, bhsharma, kexec, zengweilin

On Tue, Dec 01, 2020 at 12:06:16PM +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>
> 
> v2:
>   use goto instead of free here,based on Simon Horman's advice:
>   "Can we use the goto idiom here, as is used elsewhere in this function?"
> 
> v1: http://lists.infradead.org/pipermail/kexec/2020-November/021809.html

Thanks, applied.

_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-12-09 12:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-01  4:06 [PATCH v2] dt-ops: fix memory leak when new_node malloc fails qiuguorui1
2020-12-09 12:43 ` Simon Horman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.