While looking at bug 44397,

https://bugs.freedesktop.org/show_bug.cgi?id=44397

Gnome's volume control somehow wanted to create a filter sink cycle. I'm attaching a patch to prevent this, which seems to have worked (at least there is no crash!), but before I push it:

Is there any reason, any use case, where we actually would want a cycle? I can't think of any, but just wanted another thought in case I missed anything.


--
David Henningsson, Canonical Ltd.
http://launchpad.net/~diwic
>From c89b41abebddcb1775b75a37739c6d8d6d681b08 Mon Sep 17 00:00:00 2001
From: David Henningsson <[email protected]>
Date: Fri, 23 Mar 2012 13:06:27 +0100
Subject: [PATCH] sink: Prevent filter sink cycles

BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=44397
Signed-off-by: David Henningsson <[email protected]>
---
 src/pulsecore/sink-input.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c
index b8412bd..a8aeda6 100644
--- a/src/pulsecore/sink-input.c
+++ b/src/pulsecore/sink-input.c
@@ -1383,6 +1383,15 @@ pa_bool_t pa_sink_input_may_move(pa_sink_input *i) {
     return TRUE;
 }
 
+static pa_bool_t find_filter_sink_input(pa_sink_input *target, pa_sink *s) {
+    while (s && s->input_to_master) {
+        if (s->input_to_master == target)
+            return TRUE;
+        s = s->input_to_master->origin_sink;
+    }
+    return FALSE;
+}
+
 /* Called from main context */
 pa_bool_t pa_sink_input_may_move_to(pa_sink_input *i, pa_sink *dest) {
     pa_sink_input_assert_ref(i);
@@ -1396,6 +1405,12 @@ pa_bool_t pa_sink_input_may_move_to(pa_sink_input *i, pa_sink *dest) {
     if (!pa_sink_input_may_move(i))
         return FALSE;
 
+    /* Make sure we're not creating a filter sink cycle */
+    if (find_filter_sink_input(i, dest)) {
+        pa_log_debug("Can't connect input to %s, as that would create a cycle.", dest->name);
+        return FALSE;
+    }
+
     if (pa_idxset_size(dest->inputs) >= PA_MAX_INPUTS_PER_SINK) {
         pa_log_warn("Failed to move sink input: too many inputs per sink.");
         return FALSE;
-- 
1.7.9.1

_______________________________________________
pulseaudio-discuss mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss

Reply via email to