Skip to contentSkip to conversation

ALSA: pcmcia: Fix resource leak in snd_pdacf_probe error path

PATCH In review Haotian Zhang 2 participants 2 messages Dec 15, 2025 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: pcmcia: Fix resource leak in snd_pdacf_probe error path

When pdacf_config() fails, snd_pdacf_probe() returns the error code directly without freeing the sound card resources allocated by snd_card_new(), which leads to a memory leak.

Add proper error handling to free the sound card and clear the card list entry when pdacf_config() fails.

Fixes 15b99ac17295 ("[PATCH] pcmcia: add return value to _config() functions")
---
 sound/pcmcia/pdaudiocf/pdaudiocf.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
sound/pcmcia/pdaudiocf/pdaudiocf.c +7 -1
index 13419837dfb7..a3291e626440 100644
@@ -131,7 +131,13 @@ static int snd_pdacf_probe(struct pcmcia_device *link)
 	link->config_index = 1;
 	link->config_regs = PRESENT_OPTION;
 
-	return pdacf_config(link);
+	err = pdacf_config(link);
+	if (err < 0) {
+		card_list[i] = NULL;
+		snd_card_free(card);
+		return err;
+	}
+	return 0;
 }
 
 
Signature · 1 line
2.50.1.windows.1
#1 lore raw
Quoted 11 lines · Haotian Zhang

When pdacf_config() fails, snd_pdacf_probe() returns the error code directly without freeing the sound card resources allocated by snd_card_new(), which leads to a memory leak.

Add proper error handling to free the sound card and clear the card list entry when pdacf_config() fails.

Fixes 15b99ac17295 ("[PATCH] pcmcia: add return value to _config() functions")

Applied now. Thanks.

Takashi