Skip to content

Commit 6d03242

Browse files
elmarcoMichael Tokarev
authored and
Michael Tokarev
committed
hw/audio/hda: fix memory leak on audio setup
When SET_STREAM_FORMAT is called, we should clear the existing setup. Factor out common function to close a stream. Direct leak of 144 byte(s) in 3 object(s) allocated from: #0 0x7f91d38f7350 in calloc (/lib64/libasan.so.8+0xf7350) (BuildId: a4ad7eb954b390cf00f07fa10952988a41d9fc7a) #1 0x7f91d2ab7871 in g_malloc0 (/lib64/libglib-2.0.so.0+0x64871) (BuildId: 36b60dbd02e796145a982d0151ce37202ec05649) #2 0x562fa2f447ee in timer_new_full /home/elmarco/src/qemu/include/qemu/timer.h:538 #3 0x562fa2f4486f in timer_new /home/elmarco/src/qemu/include/qemu/timer.h:559 qemu#4 0x562fa2f448a9 in timer_new_ns /home/elmarco/src/qemu/include/qemu/timer.h:577 qemu#5 0x562fa2f47955 in hda_audio_setup ../hw/audio/hda-codec.c:490 qemu#6 0x562fa2f4897e in hda_audio_command ../hw/audio/hda-codec.c:605 Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> Message-ID: <20241008125028.1177932-3-marcandre.lureau@redhat.com> (cherry picked from commit 6d6e233) Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
1 parent 2787ca0 commit 6d03242

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

hw/audio/hda-codec.c

+20-13
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,24 @@ static void hda_audio_set_amp(HDAAudioStream *st)
472472
}
473473
}
474474

475+
static void hda_close_stream(HDAAudioState *a, HDAAudioStream *st)
476+
{
477+
if (st->node == NULL) {
478+
return;
479+
}
480+
if (a->use_timer) {
481+
timer_free(st->buft);
482+
st->buft = NULL;
483+
}
484+
if (st->output) {
485+
AUD_close_out(&a->card, st->voice.out);
486+
st->voice.out = NULL;
487+
} else {
488+
AUD_close_in(&a->card, st->voice.in);
489+
st->voice.in = NULL;
490+
}
491+
}
492+
475493
static void hda_audio_setup(HDAAudioStream *st)
476494
{
477495
bool use_timer = st->state->use_timer;
@@ -484,6 +502,7 @@ static void hda_audio_setup(HDAAudioStream *st)
484502
trace_hda_audio_format(st->node->name, st->as.nchannels,
485503
fmt2name[st->as.fmt], st->as.freq);
486504

505+
hda_close_stream(st->state, st);
487506
if (st->output) {
488507
if (use_timer) {
489508
cb = hda_audio_output_cb;
@@ -741,23 +760,11 @@ static void hda_audio_init(HDACodecDevice *hda,
741760
static void hda_audio_exit(HDACodecDevice *hda)
742761
{
743762
HDAAudioState *a = HDA_AUDIO(hda);
744-
HDAAudioStream *st;
745763
int i;
746764

747765
dprint(a, 1, "%s\n", __func__);
748766
for (i = 0; i < ARRAY_SIZE(a->st); i++) {
749-
st = a->st + i;
750-
if (st->node == NULL) {
751-
continue;
752-
}
753-
if (a->use_timer) {
754-
timer_free(st->buft);
755-
}
756-
if (st->output) {
757-
AUD_close_out(&a->card, st->voice.out);
758-
} else {
759-
AUD_close_in(&a->card, st->voice.in);
760-
}
767+
hda_close_stream(a, a->st + i);
761768
}
762769
AUD_remove_card(&a->card);
763770
}

0 commit comments

Comments
 (0)