From d8dcbd43a21f2ca605f2fbdd606cd8cb2ed61a9f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 19 Sep 2009 05:04:12 +0200 Subject: pulse: when coming back from event loop wait, check if the context still exists --- src/pulse.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'src/pulse.c') diff --git a/src/pulse.c b/src/pulse.c index 3069112..da7a2b2 100644 --- a/src/pulse.c +++ b/src/pulse.c @@ -230,11 +230,13 @@ static int context_connect(ca_context *c, ca_bool_t nofail) { pa_context_set_subscribe_callback(p->context, context_subscribe_cb, c); if (pa_context_connect(p->context, NULL, nofail ? PA_CONTEXT_NOFAIL : 0, NULL) < 0) { - ret = translate_error(pa_context_errno(p->context)); + ret = translate_error(p->context ? pa_context_errno(p->context) : PA_ERR_CONNECTIONREFUSED); - pa_context_disconnect(p->context); - pa_context_unref(p->context); - p->context = NULL; + if (p->context) { + pa_context_disconnect(p->context); + pa_context_unref(p->context); + p->context = NULL; + } return ret; } @@ -383,6 +385,13 @@ int driver_open(ca_context *c) { for (;;) { pa_context_state_t state; + if (!p->context) { + ret = translate_error(PA_ERR_CONNECTIONREFUSED); + pa_threaded_mainloop_unlock(p->mainloop); + driver_destroy(c); + return ret; + } + state = pa_context_get_state(p->context); if (state == PA_CONTEXT_READY) @@ -921,7 +930,7 @@ int driver_play(ca_context *c, uint32_t id, ca_proplist *proplist, ca_finish_cal pa_threaded_mainloop_unlock(p->mainloop); /* The operation might have been canceled due to connection termination */ - if (canceled) { + if (canceled || !p->context) { ret = CA_ERROR_DISCONNECTED; goto finish_unlocked; } @@ -1021,13 +1030,15 @@ int driver_play(ca_context *c, uint32_t id, ca_proplist *proplist, ca_finish_cal } for (;;) { - pa_stream_state_t state = pa_stream_get_state(out->stream); + pa_stream_state_t state; - if (!p->context) { + if (!p->context || !out->stream) { ret = CA_ERROR_STATE; goto finish_locked; } + state = pa_stream_get_state(out->stream); + /* Stream sucessfully created */ if (state == PA_STREAM_READY) break; @@ -1240,13 +1251,15 @@ int driver_cache(ca_context *c, ca_proplist *proplist) { } for (;;) { - pa_stream_state_t state = pa_stream_get_state(out->stream); + pa_stream_state_t state; - if (!p->context) { + if (!p->context || !out->stream) { ret = CA_ERROR_STATE; goto finish_locked; } + state = pa_stream_get_state(out->stream); + /* Stream sucessfully created and uploaded */ if (state == PA_STREAM_TERMINATED) break; -- cgit