Skip to content

Commit 3d92aa4

Browse files
wenwenwang1tiwai
authored andcommitted
ALSA: hiface: fix multiple memory leak bugs
In hiface_pcm_init(), 'rt' is firstly allocated through kzalloc(). Later on, hiface_pcm_init_urb() is invoked to initialize 'rt->out_urbs[i]'. In hiface_pcm_init_urb(), 'rt->out_urbs[i].buffer' is allocated through kzalloc(). However, if hiface_pcm_init_urb() fails, both 'rt' and 'rt->out_urbs[i].buffer' are not deallocated, leading to memory leak bugs. Also, 'rt->out_urbs[i].buffer' is not deallocated if snd_pcm_new() fails. To fix the above issues, free 'rt' and 'rt->out_urbs[i].buffer'. Fixes: a91c3fb ("Add M2Tech hiFace USB-SPDIF driver") Signed-off-by: Wenwen Wang <[email protected]> Cc: <[email protected]> Signed-off-by: Takashi Iwai <[email protected]>
1 parent c1c6c87 commit 3d92aa4

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

sound/usb/hiface/pcm.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,14 +600,13 @@ int hiface_pcm_init(struct hiface_chip *chip, u8 extra_freq)
600600
ret = hiface_pcm_init_urb(&rt->out_urbs[i], chip, OUT_EP,
601601
hiface_pcm_out_urb_handler);
602602
if (ret < 0)
603-
return ret;
603+
goto error;
604604
}
605605

606606
ret = snd_pcm_new(chip->card, "USB-SPDIF Audio", 0, 1, 0, &pcm);
607607
if (ret < 0) {
608-
kfree(rt);
609608
dev_err(&chip->dev->dev, "Cannot create pcm instance\n");
610-
return ret;
609+
goto error;
611610
}
612611

613612
pcm->private_data = rt;
@@ -620,4 +619,10 @@ int hiface_pcm_init(struct hiface_chip *chip, u8 extra_freq)
620619

621620
chip->pcm = rt;
622621
return 0;
622+
623+
error:
624+
for (i = 0; i < PCM_N_URBS; i++)
625+
kfree(rt->out_urbs[i].buffer);
626+
kfree(rt);
627+
return ret;
623628
}

0 commit comments

Comments
 (0)