Only assign context and mainloop once we have connected successfully

If we fail to connect to the the pa server, we have an assigned context
and mainloop that isn't connected. So, when PULSEAUDIO_pa_context_disconnect
is called, pa asserts and crashes the application.

Assertion 'pa_atomic_load(&(c)->_ref) >= 1' failed at pulse/context.c:1055, function pa_context_disconnect(). Aborting.
This commit is contained in:
Alistair Leslie-Hughes 2020-08-14 12:08:58 +10:00
parent 88cb4962cd
commit a69c61fbfd
1 changed files with 10 additions and 3 deletions

View File

@ -295,32 +295,39 @@ ConnectToPulseServer_Internal(pa_mainloop **_mainloop, pa_context **_context)
return SDL_SetError("pa_mainloop_new() failed");
}
*_mainloop = mainloop;
mainloop_api = PULSEAUDIO_pa_mainloop_get_api(mainloop);
SDL_assert(mainloop_api); /* this never fails, right? */
context = PULSEAUDIO_pa_context_new(mainloop_api, getAppName());
if (!context) {
PULSEAUDIO_pa_mainloop_free(mainloop);
return SDL_SetError("pa_context_new() failed");
}
*_context = context;
/* Connect to the PulseAudio server */
if (PULSEAUDIO_pa_context_connect(context, NULL, 0, NULL) < 0) {
PULSEAUDIO_pa_context_unref(context);
PULSEAUDIO_pa_mainloop_free(mainloop);
return SDL_SetError("Could not setup connection to PulseAudio");
}
do {
if (PULSEAUDIO_pa_mainloop_iterate(mainloop, 1, NULL) < 0) {
PULSEAUDIO_pa_context_unref(context);
PULSEAUDIO_pa_mainloop_free(mainloop);
return SDL_SetError("pa_mainloop_iterate() failed");
}
state = PULSEAUDIO_pa_context_get_state(context);
if (!PA_CONTEXT_IS_GOOD(state)) {
PULSEAUDIO_pa_context_unref(context);
PULSEAUDIO_pa_mainloop_free(mainloop);
return SDL_SetError("Could not connect to PulseAudio");
}
} while (state != PA_CONTEXT_READY);
*_context = context;
*_mainloop = mainloop;
return 0; /* connected and ready! */
}