summaryrefslogtreecommitdiffstats
path: root/src/plugins/pulseaudio/qpulseaudioengine.cpp
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@qt.io>2016-09-20 19:28:40 +0300
committerYoann Lopes <yoann.lopes@qt.io>2016-09-21 13:13:05 +0000
commit4bae7697257e5294721211fdd0b9bad5731f70c9 (patch)
treee001043615ec95ff762fec7aaec8950a3df7770f /src/plugins/pulseaudio/qpulseaudioengine.cpp
parentbf5c7ca718a4a84e28a17ff69c4b18abee81ff93 (diff)
PulseAudio: make code more robust
Some asynchronous operations return a pa_operation pointer, which can be null if the operation fails. In some cases we were not checking that the returned object was non null, leading to some asserts being raised in pa_operation_unref. Change-Id: Iff1cc67b7f79b758fa81d79e658debb1d737b29f Reviewed-by: Christian Stromme <christian.stromme@qt.io>
Diffstat (limited to 'src/plugins/pulseaudio/qpulseaudioengine.cpp')
-rw-r--r--src/plugins/pulseaudio/qpulseaudioengine.cpp65
1 files changed, 48 insertions, 17 deletions
diff --git a/src/plugins/pulseaudio/qpulseaudioengine.cpp b/src/plugins/pulseaudio/qpulseaudioengine.cpp
index e9510fd6a..b3d5044b7 100644
--- a/src/plugins/pulseaudio/qpulseaudioengine.cpp
+++ b/src/plugins/pulseaudio/qpulseaudioengine.cpp
@@ -170,15 +170,30 @@ static void event_cb(pa_context* context, pa_subscription_event_type_t t, uint32
case PA_SUBSCRIPTION_EVENT_NEW:
case PA_SUBSCRIPTION_EVENT_CHANGE:
switch (facility) {
- case PA_SUBSCRIPTION_EVENT_SERVER:
- pa_operation_unref(pa_context_get_server_info(context, serverInfoCallback, userdata));
+ case PA_SUBSCRIPTION_EVENT_SERVER: {
+ pa_operation *op = pa_context_get_server_info(context, serverInfoCallback, userdata);
+ if (op)
+ pa_operation_unref(op);
+ else
+ qWarning("PulseAudioService: failed to get server info");
break;
- case PA_SUBSCRIPTION_EVENT_SINK:
- pa_operation_unref(pa_context_get_sink_info_by_index(context, index, sinkInfoCallback, userdata));
+ }
+ case PA_SUBSCRIPTION_EVENT_SINK: {
+ pa_operation *op = pa_context_get_sink_info_by_index(context, index, sinkInfoCallback, userdata);
+ if (op)
+ pa_operation_unref(op);
+ else
+ qWarning("PulseAudioService: failed to get sink info");
break;
- case PA_SUBSCRIPTION_EVENT_SOURCE:
- pa_operation_unref(pa_context_get_source_info_by_index(context, index, sourceInfoCallback, userdata));
+ }
+ case PA_SUBSCRIPTION_EVENT_SOURCE: {
+ pa_operation *op = pa_context_get_source_info_by_index(context, index, sourceInfoCallback, userdata);
+ if (op)
+ pa_operation_unref(op);
+ else
+ qWarning("PulseAudioService: failed to get source info");
break;
+ }
default:
break;
}
@@ -328,11 +343,15 @@ void QPulseAudioEngine::prepare()
pa_context_set_state_callback(m_context, contextStateCallback, this);
pa_context_set_subscribe_callback(m_context, event_cb, this);
- pa_operation_unref(pa_context_subscribe(m_context,
+ pa_operation *op = pa_context_subscribe(m_context,
pa_subscription_mask_t(PA_SUBSCRIPTION_MASK_SINK |
PA_SUBSCRIPTION_MASK_SOURCE |
PA_SUBSCRIPTION_MASK_SERVER),
- NULL, NULL));
+ NULL, NULL);
+ if (op)
+ pa_operation_unref(op);
+ else
+ qWarning("PulseAudioService: failed to subscribe to context notifications");
} else {
pa_context_unref(m_context);
m_context = 0;
@@ -376,21 +395,33 @@ void QPulseAudioEngine::updateDevices()
// Get default input and output devices
pa_operation *operation = pa_context_get_server_info(m_context, serverInfoCallback, this);
- while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING)
- pa_threaded_mainloop_wait(m_mainLoop);
- pa_operation_unref(operation);
+ if (operation) {
+ while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING)
+ pa_threaded_mainloop_wait(m_mainLoop);
+ pa_operation_unref(operation);
+ } else {
+ qWarning("PulseAudioService: failed to get server info");
+ }
// Get output devices
operation = pa_context_get_sink_info_list(m_context, sinkInfoCallback, this);
- while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING)
- pa_threaded_mainloop_wait(m_mainLoop);
- pa_operation_unref(operation);
+ if (operation) {
+ while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING)
+ pa_threaded_mainloop_wait(m_mainLoop);
+ pa_operation_unref(operation);
+ } else {
+ qWarning("PulseAudioService: failed to get sink info");
+ }
// Get input devices
operation = pa_context_get_source_info_list(m_context, sourceInfoCallback, this);
- while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING)
- pa_threaded_mainloop_wait(m_mainLoop);
- pa_operation_unref(operation);
+ if (operation) {
+ while (pa_operation_get_state(operation) == PA_OPERATION_RUNNING)
+ pa_threaded_mainloop_wait(m_mainLoop);
+ pa_operation_unref(operation);
+ } else {
+ qWarning("PulseAudioService: failed to get source info");
+ }
unlock();
}