From: Takashi Iwai <tiwai@suse.de>
To: "Gen Zhang" <blackgod016574@gmail.com>
Cc: <perex@perex.cz>, <linux-kernel@vger.kernel.org>
Subject: Re: [Patch] hdac_sysfs: Fix a memory leaking bug in sound/hda/hdac_sysfs.c file of Linux 5.1
Date: Thu, 16 May 2019 10:49:43 +0200 [thread overview]
Message-ID: <s5hzhnmn5qw.wl-tiwai@suse.de> (raw)
In-Reply-To: <20190516084003.GA20821@zhanggen-UX430UQ>
On Thu, 16 May 2019 10:40:03 +0200,
Gen Zhang wrote:
>
> tree->root and tree->nodes are allocated by memory allocation
> functions. And tree is also an allocated memory. When allocation of
> tree->root and tree->nodes fails, not freeing tree will leak memory.
> Thus we should free tree in this situation.
No, the leftover is freed in the caller side by calling
widget_tree_free().
thanks,
Takashi
>
> Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
>
> ---
> diff --git a/sound/hda/hdac_sysfs.c b/sound/hda/hdac_sysfs.c
> index fb2aa34..5d8a939 100644
> --- a/sound/hda/hdac_sysfs.c
> +++ b/sound/hda/hdac_sysfs.c
> @@ -370,12 +370,12 @@ static int widget_tree_create(struct hdac_device *codec)
>
> tree->root = kobject_create_and_add("widgets", &codec->dev.kobj);
> if (!tree->root)
> - return -ENOMEM;
> + goto free_tree;
>
> tree->nodes = kcalloc(codec->num_nodes + 1, sizeof(*tree->nodes),
> GFP_KERNEL);
> if (!tree->nodes)
> - return -ENOMEM;
> + goto free_tree;
>
> for (i = 0, nid = codec->start_nid; i < codec->num_nodes; i++, nid++) {
> err = add_widget_node(tree->root, nid, &widget_node_group,
> @@ -393,6 +393,9 @@ static int widget_tree_create(struct hdac_device *codec)
>
> kobject_uevent(tree->root, KOBJ_CHANGE);
> return 0;
> +free_tree:
> + kfree(tree);
> + return -ENOMEM;
> }
>
> int hda_widget_sysfs_init(struct hdac_device *codec)
> ---
>
next prev parent reply other threads:[~2019-05-16 8:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-16 8:40 Gen Zhang
2019-05-16 8:49 ` Takashi Iwai [this message]
2019-05-16 8:59 ` Gen Zhang
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=s5hzhnmn5qw.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=blackgod016574@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=perex@perex.cz \
/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
all inboxes | Powered by JetHome®