[pulseaudio-discuss] [PATCH] stream: Prevent s->context->playback_streams from growing indefinitely when uploading and unloading samples through one context.

Tanu Kaskinen tanu.kaskinen at digia.com
Fri Nov 11 06:22:24 PST 2011

From: Antti-Ville Jansson <antti-ville.jansson at digia.com>

In pa_create_stream_callback, a stream is inserted into
s->context->record_streams only if it's a record stream. Otherwise it's
inserted into s->context->playback_streams. However, in stream_unlink the
stream is removed from s->context->playback_streams only if it's a playback
stream and otherwise it's removed from s->context->record_streams.

Thus, if the stream is an upload stream, we first insert it into
s->context->playback_streams in pa_create_stream_callback and then try to
remove it unsuccessfully from s->context->record_streams in stream_unlink. This
means that we are leaking hashmap entries until the context is freed,
constantly consuming more memory with applications that upload and unload a
large number of samples through one context.

Of course, this begs the question whether upload streams even belong in either
of those hashmaps. I don't want to mess around with the code too much at this
point though, so this patch should be a sufficient improvement.
 src/pulse/stream.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/pulse/stream.c b/src/pulse/stream.c
index 3bf2d96..5433abf 100644
--- a/src/pulse/stream.c
+++ b/src/pulse/stream.c
@@ -258,7 +258,7 @@ static void stream_unlink(pa_stream *s) {
         pa_pdispatch_unregister_reply(s->context->pdispatch, s);
     if (s->channel_valid) {
-        pa_hashmap_remove((s->direction == PA_STREAM_PLAYBACK) ? s->context->playback_streams : s->context->record_streams, PA_UINT32_TO_PTR(s->channel));
+        pa_hashmap_remove((s->direction == PA_STREAM_RECORD) ? s->context->record_streams : s->context->playback_streams, PA_UINT32_TO_PTR(s->channel));
         s->channel = 0;
         s->channel_valid = FALSE;

More information about the pulseaudio-discuss mailing list