Fix possible resource leak

This commit is contained in:
Alexander Rosenberg 2023-09-16 11:02:44 -07:00
parent bb55ac56dd
commit cf2d0ed30e
Signed by: Zander671
GPG Key ID: 5FD0394ADBD72730

View File

@ -72,6 +72,7 @@ static void cleanup(void *data_to_free[2]) {
} }
void pulse_listener_main(pthread_t *main_thread) { void pulse_listener_main(pthread_t *main_thread) {
pthread_setcanceltype(PTHREAD_CANCEL_DISABLE, NULL);
pa_mainloop *mainloop = pa_mainloop_new(); pa_mainloop *mainloop = pa_mainloop_new();
if (!mainloop) { if (!mainloop) {
ERROR("could not create pulse mainloop\n"); ERROR("could not create pulse mainloop\n");
@ -91,11 +92,12 @@ void pulse_listener_main(pthread_t *main_thread) {
(pa_context_notify_cb_t)&state_callback, (pa_context_notify_cb_t)&state_callback,
main_thread); main_thread);
if (pa_context_connect(context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL) < 0) { if (pa_context_connect(context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL) < 0) {
ERROR("could not connect to pulse"); ERROR("could not connect to pulse\n");
return; return;
} }
void *data_to_free[2] = { mainloop, context }; void *data_to_free[2] = { mainloop, context };
pthread_cleanup_push((void(*)(void *)) cleanup, data_to_free); pthread_cleanup_push((void(*)(void *)) cleanup, data_to_free);
pthread_setcanceltype(PTHREAD_CANCEL_ENABLE, NULL);
pa_mainloop_run(mainloop, NULL); pa_mainloop_run(mainloop, NULL);
pthread_cleanup_pop(1); pthread_cleanup_pop(1);
} }