Skip to contentSkip to conversation

ALSA: ctxfi: Fix memory leakage when clearing DAO input mappers

PATCH In review Harin Lee 2 participants 3 messages Oct 1 – Oct 3 Sound

lore
Share & tools
lore

Harin Lee

author
#0 lore raw

cover ALSA: ctxfi: Fix memory leakage when clearing DAO input mappers

I fixed the memory leakage in dao_clear_input() and successfully tested this patch on an AMD64 system with an OK0010 card and KASAN enabled.

However, actually I could not find any evidence for why the original commit mistakenly removed the kfree() calls.

Please feel free to drop this patch when this change looks like it has not been verified yet.

Harin Lee (1):
ALSA: ctxfi: Fix memory leakage when clearing DAO input mappers

 sound/pci/ctxfi/ctdaio.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Signature · 1 line
2.55.0
author
#1 lore raw

PATCH 1/1 ALSA: ctxfi: Fix memory leakage when clearing DAO input mappers

Commit e576e7843c0d ("ALSA: ctxfi: Simplify dao_clear_{left,right}_input() functions") centralized the DAO input mapper clearing logic in
dao_clear_input(), but omitted the kfree() calls.

It removes the mapper entries from the list and sets their pointers to NULL without freeing the allocated array. This leaks memory each time dao_clear_input() is called.

Store the base pointer of the allocation before clearing the mapper entries and free the array after removing entries from the list.

Fixes e576e7843c0d ("ALSA: ctxfi: Simplify dao_clear_{left,right}_input() functions")
---
 sound/pci/ctxfi/ctdaio.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
sound/pci/ctxfi/ctdaio.c +5 -1
index 9be70c6862ab..27e502fa493e 100644
@@ -221,14 +221,18 @@ static int dao_set_right_input(struct dao *dao, struct rsc *input)
 
 static int dao_clear_input(struct dao *dao, unsigned int start, unsigned int end)
 {
+	struct imapper *entry;
 	unsigned int i;
 
-	if (!dao->imappers[start])
+	entry = dao->imappers[start];
+	if (!entry)
 		return 0;
+
 	for (i = start; i < end; i++) {
 		dao->mgr->imap_delete(dao->mgr, dao->imappers[i]);
 		dao->imappers[i] = NULL;
 	}
+	kfree(entry);
 
 	return 0;
 }
Signature · 1 line
2.55.0
#2 lore raw
Quoted 9 lines · Harin Lee

Commit e576e7843c0d ("ALSA: ctxfi: Simplify dao_clear_{left,right}_input() functions") centralized the DAO input mapper clearing logic in
dao_clear_input(), but omitted the kfree() calls.

It removes the mapper entries from the list and sets their pointers to NULL without freeing the allocated array. This leaks memory each time dao_clear_input() is called.

Quoted 6 lines

Store the base pointer of the allocation before clearing the mapper entries and free the array after removing entries from the list.

Fixes e576e7843c0d ("ALSA: ctxfi: Simplify dao_clear_{left,right}_input() functions")

Applied now. Thanks.

Takashi