lkml.org 
[lkml]   [2022]   [Mar]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH -next] ASoC: SOF: topology: Fix memory leak in sof_control_load()
Date
scontrol doesn't get freed when kstrdup returns NULL.
Fix by free iscontrol in that case.

scontrol = kzalloc(sizeof(*scontrol), GFP_KERNEL);
if (!scontrol)
return -ENOMEM;

scontrol->name = kstrdup(hdr->name, GFP_KERNEL);
if (!scontrol->name)
return -ENOMEM;

Signed-off-by: Yu Liao <liaoyu15@huawei.com>
---
sound/soc/sof/topology.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c
index 367fbe2d5b31..88f34f43d693 100644
--- a/sound/soc/sof/topology.c
+++ b/sound/soc/sof/topology.c
@@ -905,8 +905,10 @@ static int sof_control_load(struct snd_soc_component *scomp, int index,
return -ENOMEM;

scontrol->name = kstrdup(hdr->name, GFP_KERNEL);
- if (!scontrol->name)
+ if (!scontrol->name) {
+ kfree(scontrol);
return -ENOMEM;
+ }

scontrol->scomp = scomp;
scontrol->access = kc->access;
--
2.25.1
\
 
 \ /
  Last update: 2022-03-18 03:08    [W:3.566 / U:0.008 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site