[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stable-9.1.2 71/72] hw/audio/hda: fix memory leak on audio setup
From: |
Michael Tokarev |
Subject: |
[Stable-9.1.2 71/72] hw/audio/hda: fix memory leak on audio setup |
Date: |
Tue, 19 Nov 2024 09:04:12 +0300 |
From: Paolo Bonzini <pbonzini@redhat.com>
When SET_STREAM_FORMAT is called, the st->buft timer is overwritten, thus
causing a memory leak. This was originally fixed in commit 816139ae6a5
("hw/audio/hda: fix memory leak on audio setup", 2024-11-14) but that
caused the audio to break in SPICE.
Fortunately, a simpler fix is possible. The timer only needs to be
reset, because the callback is always the same (st->output is set at
realize time in hda_audio_init); call to timer_new_ns overkill. Replace
it with timer_del and only initialize the timer once; for simplicity,
do it even if use_timer is false.
An even simpler fix would be to free the old time in hda_audio_setup().
However, it seems better to place the initialization of the timer close
to that of st->ouput.
Cc: qemu-stable@nongnu.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Michael Tokarev <mjt@tls.msk.ru>
Message-ID: <20241114125318.1707590-3-pbonzini@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
(cherry picked from commit 626b39006d2f9b1378a04cb88a2187bb852cb055)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
diff --git a/hw/audio/hda-codec.c b/hw/audio/hda-codec.c
index ee3d0a7dec..407d670d82 100644
--- a/hw/audio/hda-codec.c
+++ b/hw/audio/hda-codec.c
@@ -487,8 +487,7 @@ static void hda_audio_setup(HDAAudioStream *st)
if (st->output) {
if (use_timer) {
cb = hda_audio_output_cb;
- st->buft = timer_new_ns(QEMU_CLOCK_VIRTUAL,
- hda_audio_output_timer, st);
+ timer_del(st->buft);
} else {
cb = hda_audio_compat_output_cb;
}
@@ -497,8 +496,7 @@ static void hda_audio_setup(HDAAudioStream *st)
} else {
if (use_timer) {
cb = hda_audio_input_cb;
- st->buft = timer_new_ns(QEMU_CLOCK_VIRTUAL,
- hda_audio_input_timer, st);
+ timer_del(st->buft);
} else {
cb = hda_audio_compat_input_cb;
}
@@ -726,8 +724,12 @@ static void hda_audio_init(HDACodecDevice *hda,
st->gain_right = QEMU_HDA_AMP_STEPS;
st->compat_bpos = sizeof(st->compat_buf);
st->output = true;
+ st->buft = timer_new_ns(QEMU_CLOCK_VIRTUAL,
+ hda_audio_output_timer, st);
} else {
st->output = false;
+ st->buft = timer_new_ns(QEMU_CLOCK_VIRTUAL,
+ hda_audio_input_timer, st);
}
st->format = AC_FMT_TYPE_PCM | AC_FMT_BITS_16 |
(1 << AC_FMT_CHAN_SHIFT);
@@ -750,9 +752,7 @@ static void hda_audio_exit(HDACodecDevice *hda)
if (st->node == NULL) {
continue;
}
- if (a->use_timer) {
- timer_free(st->buft);
- }
+ timer_free(st->buft);
if (st->output) {
AUD_close_out(&a->card, st->voice.out);
} else {
--
2.39.5
- [Stable-9.1.2 61/72] target/arm: Drop user-only special case in sve_stN_r, (continued)
- [Stable-9.1.2 61/72] target/arm: Drop user-only special case in sve_stN_r, Michael Tokarev, 2024/11/19
- [Stable-9.1.2 63/72] linux-user: Tolerate CONFIG_LSM_MMAP_MIN_ADDR, Michael Tokarev, 2024/11/19
- [Stable-9.1.2 62/72] accel/tcg: Fix user-only probe_access_internal plugin check, Michael Tokarev, 2024/11/19
- [Stable-9.1.2 65/72] linux-user/arm: Select vdso for be8 and be32 modes, Michael Tokarev, 2024/11/19
- [Stable-9.1.2 66/72] tcg: Allow top bit of SIMD_DATA_BITS to be set in simd_desc(), Michael Tokarev, 2024/11/19
- [Stable-9.1.2 64/72] linux-user/arm: Reduce vdso alignment to 4k, Michael Tokarev, 2024/11/19
- [Stable-9.1.2 67/72] target/i386: fix hang when using slow path for ptw_setl, Michael Tokarev, 2024/11/19
- [Stable-9.1.2 68/72] vfio/container: Fix container object destruction, Michael Tokarev, 2024/11/19
- [Stable-9.1.2 69/72] hw/misc/mos6522: Fix bad class definition of the MOS6522 device, Michael Tokarev, 2024/11/19
- [Stable-9.1.2 70/72] Revert "hw/audio/hda: fix memory leak on audio setup", Michael Tokarev, 2024/11/19
- [Stable-9.1.2 71/72] hw/audio/hda: fix memory leak on audio setup,
Michael Tokarev <=
- [Stable-9.1.2 72/72] usb-hub: Fix handling port power control messages, Michael Tokarev, 2024/11/19