Ensure pulse gets cleaned up

This commit is contained in:
Alexander Rosenberg 2023-09-09 00:31:15 -07:00
parent 26b304eeb3
commit cc78fe00af
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730
2 changed files with 10 additions and 1 deletions

View File

@ -213,7 +213,8 @@ void statusloop() {
void stopthreads() { void stopthreads() {
for (int i = 0; i < LENGTH(thread_callbacks); ++i) { for (int i = 0; i < LENGTH(thread_callbacks); ++i) {
pthread_kill(threads[i], SIGTERM); pthread_cancel(threads[i]);
pthread_join(threads[i], NULL);
} }
} }

View File

@ -66,6 +66,11 @@ static void state_callback(pa_context *ctx, pthread_t *main_thread) {
} }
} }
static void cleanup(void *data_to_free[2]) {
pa_context_unref(data_to_free[1]);
pa_mainloop_free(data_to_free[0]);
}
void pulse_listener_main(pthread_t *main_thread) { void pulse_listener_main(pthread_t *main_thread) {
pa_mainloop *mainloop = pa_mainloop_new(); pa_mainloop *mainloop = pa_mainloop_new();
if (!mainloop) { if (!mainloop) {
@ -89,5 +94,8 @@ void pulse_listener_main(pthread_t *main_thread) {
ERROR("could not connect to pulse"); ERROR("could not connect to pulse");
return; return;
} }
void *data_to_free[2] = { mainloop, context };
pthread_cleanup_push((void(*)(void *)) cleanup, data_to_free);
pa_mainloop_run(mainloop, NULL); pa_mainloop_run(mainloop, NULL);
pthread_cleanup_pop(1);
} }