From a53b371a4f6ec373b1c76020c721039e9cd1eb92 Mon Sep 17 00:00:00 2001 From: Georg Chini Date: Sun, 3 Feb 2019 19:13:22 +0100 Subject: [PATCH] virtual-source: Fix crash in combination with module-loopback Similar to module-tunnel-sink-new, module-virtual-source did not create a rtpoll for the uplink sink. This lead to a crash when the uplink sink was used by module loopback, because module-loopback relies on the sink to provide a rtpoll. Additionally, the sink was not unlinked when the module was unloaded. This patch fixes both issues. The rtpoll created is never run by the sink, so the patch is no real fix but just a workaround to make module-loopback happy. --- src/modules/module-virtual-source.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/modules/module-virtual-source.c b/src/modules/module-virtual-source.c index ba8c52be7..0c9817813 100644 --- a/src/modules/module-virtual-source.c +++ b/src/modules/module-virtual-source.c @@ -38,6 +38,7 @@ #include #include #include +#include PA_MODULE_AUTHOR("Pierre-Louis Bossart"); PA_MODULE_DESCRIPTION("Virtual source"); @@ -77,6 +78,7 @@ struct userdata { pa_sink *sink; pa_usec_t block_usec; pa_memblockq *sink_memblockq; + pa_rtpoll *rtpoll; }; @@ -543,6 +545,13 @@ int pa__init(pa_module*m) { } u->channels = ss.channels; + /* The rtpoll created here is never run. It is only necessary to avoid crashes + * when module-virtual-source is used together with module-loopback or + * module-combine-sink. Both modules base their asyncmsq on the rtpoll provided + * by the sink. module-loopback and combine-sink only work because they + * call pa_asyncmsq_process_one() themselves. */ + u->rtpoll = pa_rtpoll_new(); + /* Create source */ pa_source_new_data_init(&source_data); source_data.driver = __FILE__; @@ -671,6 +680,7 @@ int pa__init(pa_module*m) { u->sink->userdata = u; pa_sink_set_asyncmsgq(u->sink, master->asyncmsgq); + pa_sink_set_rtpoll(u->sink, u->rtpoll); /* FIXME: no idea what I am doing here */ u->block_usec = BLOCK_USEC; @@ -732,8 +742,10 @@ void pa__done(pa_module*m) { if (u->source) pa_source_unref(u->source); - if (u->sink) + if (u->sink) { + pa_sink_unlink(u->sink); pa_sink_unref(u->sink); + } if (u->memblockq) pa_memblockq_free(u->memblockq); @@ -741,5 +753,8 @@ void pa__done(pa_module*m) { if (u->sink_memblockq) pa_memblockq_free(u->sink_memblockq); + if (u->rtpoll) + pa_rtpoll_free(u->rtpoll); + pa_xfree(u); }