[Spice-devel] [spice-gtk] Fix SndCodec leak in playback_handle_start()

Christophe Fergeau cfergeau at redhat.com
Wed Oct 22 07:58:39 PDT 2014


An audio SpiceChannel can get several times the 'start' message during
its lifetime. If received multiple times (for example when rebooting a
VM), this would lead to a SndCodec leak as reported by valgrind:

==7749== 27,036 (48 direct, 26,988 indirect) bytes in 1 blocks are definitely lost in loss record 11,418 of 11,440
==7749==    at 0x4A08946: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==7749==    by 0x5772A9A: spice_malloc0 (mem.c:109)
==7749==    by 0x5772D42: spice_malloc0_n (mem.c:173)
==7749==    by 0x57FB3E2: snd_codec_create (snd_codec.c:267)
==7749==    by 0x573774C: playback_handle_start (channel-playback.c:380)
==7749==    by 0x5721E44: spice_channel_handle_msg (spice-channel.c:2859)
==7749==    by 0x571ECB3: spice_channel_recv_msg (spice-channel.c:1877)
==7749==    by 0x571F402: spice_channel_iterate_read (spice-channel.c:2114)
==7749==    by 0x571F614: spice_channel_iterate (spice-channel.c:2152)
==7749==    by 0x5720411: spice_channel_coroutine (spice-channel.c:2429)
==7749==    by 0x575CD3A: coroutine_trampoline (coroutine_ucontext.c:63)
==7749==    by 0x575C9F4: continuation_trampoline (continuation.c:55)
==7749==    by 0x3898E47FEF: ??? (in /usr/lib64/libc-2.20.so)
==7749==    by 0xAED547666C92C2FF: ???
==7749==    by 0xFFEFFF92F: ???
---
 gtk/channel-playback.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gtk/channel-playback.c b/gtk/channel-playback.c
index e5b9658..40e01ba 100644
--- a/gtk/channel-playback.c
+++ b/gtk/channel-playback.c
@@ -375,6 +375,7 @@ static void playback_handle_start(SpiceChannel *channel, SpiceMsgIn *in)
     c->codec = NULL;
 
     if (c->mode != SPICE_AUDIO_DATA_MODE_RAW) {
+        snd_codec_destroy(&c->codec);
         if (snd_codec_create(&c->codec, c->mode, start->frequency, SND_CODEC_DECODE) != SND_CODEC_OK) {
             g_warning("create decoder failed");
             return;
-- 
2.1.0



More information about the Spice-devel mailing list