Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Horman <horms@verge.net.au>
To: qiuguorui1 <qiuguorui1@huawei.com>
Cc: leeyou.li@huawei.com, bhsharma@redhat.com,
	kexec@lists.infradead.org, zengweilin@huawei.com
Subject: Re: [PATCH] dt-ops: fix memory leak when new_node malloc fails
Date: Mon, 30 Nov 2020 17:39:08 +0100	[thread overview]
Message-ID: <20201130163907.GC20208@vergenet.net> (raw)
In-Reply-To: <20201130064156.2208-1-qiuguorui1@huawei.com>

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

  reply	other threads:[~2020-11-30 16:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-30  6:41 [PATCH] dt-ops: fix memory leak when new_node malloc fails qiuguorui1
2020-11-30 16:39 ` Simon Horman [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-12-01  3:11 qiuguorui

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201130163907.GC20208@vergenet.net \
    --to=horms@verge.net.au \
    --cc=bhsharma@redhat.com \
    --cc=kexec@lists.infradead.org \
    --cc=leeyou.li@huawei.com \
    --cc=qiuguorui1@huawei.com \
    --cc=zengweilin@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox