From cc78fe00af9d429732ab0fab5d12f89ca9135037 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Sat, 9 Sep 2023 00:31:15 -0700 Subject: [PATCH] Ensure pulse gets cleaned up --- dwmblocks.c | 3 ++- pulse-listener.c | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/dwmblocks.c b/dwmblocks.c index c987dbe..4345d19 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -213,7 +213,8 @@ void statusloop() { void stopthreads() { for (int i = 0; i < LENGTH(thread_callbacks); ++i) { - pthread_kill(threads[i], SIGTERM); + pthread_cancel(threads[i]); + pthread_join(threads[i], NULL); } } diff --git a/pulse-listener.c b/pulse-listener.c index b4cb769..c1d6a17 100644 --- a/pulse-listener.c +++ b/pulse-listener.c @@ -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) { pa_mainloop *mainloop = pa_mainloop_new(); if (!mainloop) { @@ -89,5 +94,8 @@ void pulse_listener_main(pthread_t *main_thread) { ERROR("could not connect to pulse"); return; } + void *data_to_free[2] = { mainloop, context }; + pthread_cleanup_push((void(*)(void *)) cleanup, data_to_free); pa_mainloop_run(mainloop, NULL); + pthread_cleanup_pop(1); }