PulseAudio: fix crash when failing to create a context.
authorYoann Lopes <yoann.lopes@digia.com>
Fri, 13 Dec 2013 14:37:50 +0000 (15:37 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 6 Jan 2014 14:45:48 +0000 (15:45 +0100)
Don't try to call a function on a null PulseAudio context.
If pa_context_new() fails, we now try again to connect to the pulse
audio daemon later.

Task-number: QTBUG-35456
Change-Id: I0b848d3f25f57651ab31b9eca7ceb1bc9df2f682
Reviewed-by: Christian Stromme <christian.stromme@digia.com>
src/multimedia/audio/qsoundeffect_pulse_p.cpp

index 8bac6c9..23e8d72 100644 (file)
@@ -183,16 +183,17 @@ private Q_SLOTS:
         lock();
         m_context = pa_context_new(m_mainLoopApi, QString(QLatin1String("QtPulseAudio:%1")).arg(::getpid()).toLatin1().constData());
 
-        pa_context_set_state_callback(m_context, context_state_callback, this);
-
         if (m_context == 0) {
             qWarning("PulseAudioService: Unable to create new pulseaudio context");
             pa_threaded_mainloop_unlock(m_mainLoop);
             pa_threaded_mainloop_free(m_mainLoop);
             m_mainLoop = 0;
+            onContextFailed();
             return;
         }
 
+        pa_context_set_state_callback(m_context, context_state_callback, this);
+
         if (pa_context_connect(m_context, 0, (pa_context_flags_t)0, 0) < 0) {
             qWarning("PulseAudioService: pa_context_connect() failed");
             pa_context_unref(m_context);