ALSA: ctxfi: Fix memory leakage when clearing DAO input mappers
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
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 indao_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.
--- sound/pci/ctxfi/ctdaio.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
sound/pci/ctxfi/ctdaio.c +5 -1
@@ -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
Quoted 9 lines · Harin Lee
Commit
e576e7843c0d("ALSA: ctxfi: Simplify dao_clear_{left,right}_input() functions") centralized the DAO input mapper clearing logic indao_clear_input(), but omitted thekfree()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")Signed-off-by Harin Lee <[email protected]>
Applied now. Thanks.
Takashi