Skip to contentSkip to conversation

ALSA: hda: fix potential memleak in 'add_widget_node'

PATCH Applied Ye Bin 2 participants 2 messages Nov 10, 2022 Sound

lore
Share & tools
lore

Ye Bin

author
#0 lore raw

PATCH 1/1 ALSA: hda: fix potential memleak in 'add_widget_node'

From: Ye Bin <[email protected]>

As 'kobject_add' may allocated memory for 'kobject->name' when return error. And in this function, if call 'kobject_add' failed didn't free kobject. So call 'kobject_put' to recycling resources.

---
 sound/hda/hdac_sysfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
sound/hda/hdac_sysfs.c +3 -1
index e47de49a32e3..62a9615dcf52 100644
@@ -346,8 +346,10 @@ static int add_widget_node(struct kobject *parent, hda_nid_t nid,
 		return -ENOMEM;
 	kobject_init(kobj, &widget_ktype);
 	err = kobject_add(kobj, parent, "%02x", nid);
-	if (err < 0)
+	if (err < 0) {
+		kobject_put(kobj);
 		return err;
+	}
 	err = sysfs_create_group(kobj, group);
 	if (err < 0) {
 		kobject_put(kobj);
Signature · 1 line
2.31.1
Applied
#1 lore raw
Quoted 8 lines · Ye Bin

From: Ye Bin <[email protected]>

As 'kobject_add' may allocated memory for 'kobject->name' when return error. And in this function, if call 'kobject_add' failed didn't free kobject. So call 'kobject_put' to recycling resources.

Thanks, applied now.

Takashi