mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-20 06:59:53 -05:00
tunnel modules: Fix crash when the module was unloaded while waiting for re-init
When the tunnel modules had no connection and a re-init was pending, the module could be unloaded without cancelling the pending re-init. When the timer expired in that situation, this lead to a crash. This patch fixes the problem by keeping a reference when the module is scheduled to be re-initialized. Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/705>
This commit is contained in:
parent
c3d1db2f28
commit
363a384143
5 changed files with 233 additions and 61 deletions
|
|
@ -30,31 +30,49 @@
|
|||
#include <pulsecore/core.h>
|
||||
#include <pulsecore/thread-mq.h>
|
||||
|
||||
struct reinit_data {
|
||||
struct pa_restart_data {
|
||||
init_cb do_init;
|
||||
done_cb do_done;
|
||||
|
||||
pa_usec_t restart_usec;
|
||||
pa_module *module;
|
||||
pa_time_event *time_event;
|
||||
pa_defer_event *defer_event;
|
||||
};
|
||||
|
||||
static void do_reinit(pa_mainloop_api *mainloop, pa_restart_data *rd);
|
||||
|
||||
static void call_init(pa_mainloop_api *mainloop, pa_time_event *e, const struct timeval *tv, void *userdata) {
|
||||
struct reinit_data *rd = userdata;
|
||||
pa_restart_data *rd = userdata;
|
||||
int ret;
|
||||
|
||||
if (rd->time_event) {
|
||||
mainloop->time_free(rd->time_event);
|
||||
rd->time_event = NULL;
|
||||
}
|
||||
|
||||
/* now that restart_usec has elapsed, we call do_init to restart the module */
|
||||
ret = rd->do_init(rd->module);
|
||||
|
||||
/* if the init failed, we got here because the caller wanted to restart, so
|
||||
* setup another restart */
|
||||
if (ret < 0)
|
||||
pa_restart_module_reinit(rd->module, rd->do_init, rd->do_done, rd->restart_usec);
|
||||
|
||||
pa_xfree(rd);
|
||||
do_reinit(mainloop, rd);
|
||||
}
|
||||
|
||||
static void do_reinit(pa_mainloop_api *mainloop, void *userdata) {
|
||||
struct reinit_data *rd = userdata;
|
||||
static void defer_callback(pa_mainloop_api *mainloop, pa_defer_event *e, void *userdata) {
|
||||
pa_restart_data *rd = userdata;
|
||||
|
||||
pa_assert(rd->defer_event == e);
|
||||
|
||||
mainloop->defer_enable(rd->defer_event, 0);
|
||||
mainloop->defer_free(rd->defer_event);
|
||||
rd->defer_event = NULL;
|
||||
|
||||
do_reinit(mainloop, rd);
|
||||
}
|
||||
|
||||
static void do_reinit(pa_mainloop_api *mainloop, pa_restart_data *rd) {
|
||||
struct timeval tv;
|
||||
|
||||
pa_assert_ctl_context();
|
||||
|
|
@ -66,17 +84,20 @@ static void do_reinit(pa_mainloop_api *mainloop, void *userdata) {
|
|||
/* after restart_usec, call do_init to restart the module */
|
||||
pa_gettimeofday(&tv);
|
||||
pa_timeval_add(&tv, rd->restart_usec);
|
||||
mainloop->time_new(mainloop, &tv, call_init, rd);
|
||||
rd->time_event = mainloop->time_new(mainloop, &tv, call_init, rd);
|
||||
}
|
||||
|
||||
void pa_restart_module_reinit(pa_module *m, init_cb do_init, done_cb do_done, pa_usec_t restart_usec) {
|
||||
struct reinit_data *rd;
|
||||
pa_restart_data *pa_restart_module_reinit(pa_module *m, init_cb do_init, done_cb do_done, pa_usec_t restart_usec) {
|
||||
pa_restart_data *rd;
|
||||
|
||||
pa_assert_ctl_context();
|
||||
pa_assert(do_init);
|
||||
pa_assert(do_done);
|
||||
pa_assert(restart_usec);
|
||||
|
||||
pa_log_info("Starting reinit for %s", m->name);
|
||||
|
||||
rd = pa_xnew0(struct reinit_data, 1);
|
||||
rd = pa_xnew0(pa_restart_data, 1);
|
||||
rd->do_init = do_init;
|
||||
rd->do_done = do_done;
|
||||
rd->restart_usec = restart_usec;
|
||||
|
|
@ -84,5 +105,25 @@ void pa_restart_module_reinit(pa_module *m, init_cb do_init, done_cb do_done, pa
|
|||
|
||||
/* defer actually doing a reinit, so that we can safely exit whatever call
|
||||
* chain we're in before we effectively reinit the module */
|
||||
pa_mainloop_api_once(m->core->mainloop, do_reinit, rd);
|
||||
rd->defer_event = m->core->mainloop->defer_new(m->core->mainloop, defer_callback, rd);
|
||||
m->core->mainloop->defer_enable(rd->defer_event, 1);
|
||||
|
||||
return rd;
|
||||
}
|
||||
|
||||
void pa_restart_free(pa_restart_data *rd) {
|
||||
pa_assert_ctl_context();
|
||||
pa_assert(rd);
|
||||
|
||||
if (rd->defer_event) {
|
||||
rd->module->core->mainloop->defer_enable(rd->defer_event, 0);
|
||||
rd->module->core->mainloop->defer_free(rd->defer_event);
|
||||
}
|
||||
|
||||
if (rd->time_event) {
|
||||
pa_log_info("Cancel reinit for %s", rd->module->name);
|
||||
rd->module->core->mainloop->time_free(rd->time_event);
|
||||
}
|
||||
|
||||
pa_xfree(rd);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue