[pulseaudio-discuss] [PATCH] Avoid crash by not updating volume on shutdown

David Henningsson david.henningsson at canonical.com
Mon Sep 12 03:57:20 PDT 2011


Sometimes the ALSA mixer can be modified during a point at shutdown
which causes a race condition trying to update the volume of an
unlinked sink.

BugLink: http://bugs.launchpad.net/bugs/841968
Signed-off-by: David Henningsson <david.henningsson at canonical.com>
---
 src/modules/alsa/alsa-sink.c   |    3 +++
 src/modules/alsa/alsa-source.c |    3 +++
 src/pulsecore/sink.c           |    2 ++
 src/pulsecore/source.c         |    2 ++
 4 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index 2394455..b0e4b04 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -1212,6 +1212,9 @@ static int ctl_mixer_callback(snd_mixer_elem_t *elem, unsigned int mask) {
     if (mask == SND_CTL_EVENT_MASK_REMOVE)
         return 0;
 
+    if (!PA_SOURCE_IS_LINKED(u->sink->state))
+        return 0;
+
     if (u->sink->suspend_cause & PA_SUSPEND_SESSION)
         return 0;
 
diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c
index fa8d892..b798ddb 100644
--- a/src/modules/alsa/alsa-source.c
+++ b/src/modules/alsa/alsa-source.c
@@ -1063,6 +1063,9 @@ static int ctl_mixer_callback(snd_mixer_elem_t *elem, unsigned int mask) {
     if (mask == SND_CTL_EVENT_MASK_REMOVE)
         return 0;
 
+    if (!PA_SOURCE_IS_LINKED(u->source->state))
+        return 0;
+
     if (u->source->suspend_cause & PA_SUSPEND_SESSION)
         return 0;
 
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 041295c..d0245df 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -2619,6 +2619,8 @@ int pa_sink_process_msg(pa_msgobject *o, int code, void *userdata, int64_t offse
         case PA_SINK_MESSAGE_UPDATE_VOLUME_AND_MUTE:
             /* This message is sent from IO-thread and handled in main thread. */
             pa_assert_ctl_context();
+            if (!PA_SINK_IS_LINKED(s->state))
+                return 0;
 
             pa_sink_get_volume(s, TRUE);
             pa_sink_get_mute(s, TRUE);
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index bc951af..ab7605d 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -2041,6 +2041,8 @@ int pa_source_process_msg(pa_msgobject *object, int code, void *userdata, int64_
         case PA_SOURCE_MESSAGE_UPDATE_VOLUME_AND_MUTE:
             /* This message is sent from IO-thread and handled in main thread. */
             pa_assert_ctl_context();
+            if (!PA_SOURCE_IS_LINKED(s->state))
+                return 0;
 
             pa_source_get_volume(s, TRUE);
             pa_source_get_mute(s, TRUE);
-- 
1.7.5.4



More information about the pulseaudio-discuss mailing list