mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	libpulse: Store pa_stream pointers to hashmaps instead of dynarrays.
Since the stream identifiers (channels) are monotonically growing integer, it isn't a good idea to use them as index to a dynamic array, because the array will grow all the time. This is not a problem with client connections that don't create many streams, but, for example, long-running clients that use libcanberra for playing event sounds, this means that the client connection effectively leaks memory.
This commit is contained in:
		
							parent
							
								
									118466638a
								
							
						
					
					
						commit
						4c793cfc76
					
				
					 3 changed files with 17 additions and 18 deletions
				
			
		| 
						 | 
				
			
			@ -199,7 +199,7 @@ static void stream_unlink(pa_stream *s) {
 | 
			
		|||
        pa_pdispatch_unregister_reply(s->context->pdispatch, s);
 | 
			
		||||
 | 
			
		||||
    if (s->channel_valid) {
 | 
			
		||||
        pa_dynarray_put((s->direction == PA_STREAM_PLAYBACK) ? s->context->playback_streams : s->context->record_streams, s->channel, NULL);
 | 
			
		||||
        pa_hashmap_remove((s->direction == PA_STREAM_PLAYBACK) ? s->context->playback_streams : s->context->record_streams, PA_UINT32_TO_PTR(s->channel));
 | 
			
		||||
        s->channel = 0;
 | 
			
		||||
        s->channel_valid = FALSE;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -354,7 +354,7 @@ void pa_command_stream_killed(pa_pdispatch *pd, uint32_t command, uint32_t tag,
 | 
			
		|||
        goto finish;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!(s = pa_dynarray_get(command == PA_COMMAND_PLAYBACK_STREAM_KILLED ? c->playback_streams : c->record_streams, channel)))
 | 
			
		||||
    if (!(s = pa_hashmap_get(command == PA_COMMAND_PLAYBACK_STREAM_KILLED ? c->playback_streams : c->record_streams, PA_UINT32_TO_PTR(channel))))
 | 
			
		||||
        goto finish;
 | 
			
		||||
 | 
			
		||||
    if (s->state != PA_STREAM_READY)
 | 
			
		||||
| 
						 | 
				
			
			@ -474,7 +474,7 @@ void pa_command_stream_moved(pa_pdispatch *pd, uint32_t command, uint32_t tag, p
 | 
			
		|||
        goto finish;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!(s = pa_dynarray_get(command == PA_COMMAND_PLAYBACK_STREAM_MOVED ? c->playback_streams : c->record_streams, channel)))
 | 
			
		||||
    if (!(s = pa_hashmap_get(command == PA_COMMAND_PLAYBACK_STREAM_MOVED ? c->playback_streams : c->record_streams, PA_UINT32_TO_PTR(channel))))
 | 
			
		||||
        goto finish;
 | 
			
		||||
 | 
			
		||||
    if (s->state != PA_STREAM_READY)
 | 
			
		||||
| 
						 | 
				
			
			@ -557,7 +557,7 @@ void pa_command_stream_buffer_attr(pa_pdispatch *pd, uint32_t command, uint32_t
 | 
			
		|||
        goto finish;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!(s = pa_dynarray_get(command == PA_COMMAND_PLAYBACK_BUFFER_ATTR_CHANGED ? c->playback_streams : c->record_streams, channel)))
 | 
			
		||||
    if (!(s = pa_hashmap_get(command == PA_COMMAND_PLAYBACK_BUFFER_ATTR_CHANGED ? c->playback_streams : c->record_streams, PA_UINT32_TO_PTR(channel))))
 | 
			
		||||
        goto finish;
 | 
			
		||||
 | 
			
		||||
    if (s->state != PA_STREAM_READY)
 | 
			
		||||
| 
						 | 
				
			
			@ -609,7 +609,7 @@ void pa_command_stream_suspended(pa_pdispatch *pd, uint32_t command, uint32_t ta
 | 
			
		|||
        goto finish;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!(s = pa_dynarray_get(command == PA_COMMAND_PLAYBACK_STREAM_SUSPENDED ? c->playback_streams : c->record_streams, channel)))
 | 
			
		||||
    if (!(s = pa_hashmap_get(command == PA_COMMAND_PLAYBACK_STREAM_SUSPENDED ? c->playback_streams : c->record_streams, PA_UINT32_TO_PTR(channel))))
 | 
			
		||||
        goto finish;
 | 
			
		||||
 | 
			
		||||
    if (s->state != PA_STREAM_READY)
 | 
			
		||||
| 
						 | 
				
			
			@ -651,7 +651,7 @@ void pa_command_stream_started(pa_pdispatch *pd, uint32_t command, uint32_t tag,
 | 
			
		|||
        goto finish;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!(s = pa_dynarray_get(c->playback_streams, channel)))
 | 
			
		||||
    if (!(s = pa_hashmap_get(c->playback_streams, PA_UINT32_TO_PTR(channel))))
 | 
			
		||||
        goto finish;
 | 
			
		||||
 | 
			
		||||
    if (s->state != PA_STREAM_READY)
 | 
			
		||||
| 
						 | 
				
			
			@ -697,7 +697,7 @@ void pa_command_stream_event(pa_pdispatch *pd, uint32_t command, uint32_t tag, p
 | 
			
		|||
        goto finish;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!(s = pa_dynarray_get(command == PA_COMMAND_PLAYBACK_STREAM_EVENT ? c->playback_streams : c->record_streams, channel)))
 | 
			
		||||
    if (!(s = pa_hashmap_get(command == PA_COMMAND_PLAYBACK_STREAM_EVENT ? c->playback_streams : c->record_streams, PA_UINT32_TO_PTR(channel))))
 | 
			
		||||
        goto finish;
 | 
			
		||||
 | 
			
		||||
    if (s->state != PA_STREAM_READY)
 | 
			
		||||
| 
						 | 
				
			
			@ -733,7 +733,7 @@ void pa_command_request(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tag
 | 
			
		|||
        goto finish;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!(s = pa_dynarray_get(c->playback_streams, channel)))
 | 
			
		||||
    if (!(s = pa_hashmap_get(c->playback_streams, PA_UINT32_TO_PTR(channel))))
 | 
			
		||||
        goto finish;
 | 
			
		||||
 | 
			
		||||
    if (s->state != PA_STREAM_READY)
 | 
			
		||||
| 
						 | 
				
			
			@ -767,7 +767,7 @@ void pa_command_overflow_or_underflow(pa_pdispatch *pd, uint32_t command, uint32
 | 
			
		|||
        goto finish;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!(s = pa_dynarray_get(c->playback_streams, channel)))
 | 
			
		||||
    if (!(s = pa_hashmap_get(c->playback_streams, PA_UINT32_TO_PTR(channel))))
 | 
			
		||||
        goto finish;
 | 
			
		||||
 | 
			
		||||
    if (s->state != PA_STREAM_READY)
 | 
			
		||||
| 
						 | 
				
			
			@ -997,7 +997,7 @@ void pa_create_stream_callback(pa_pdispatch *pd, uint32_t command, uint32_t tag,
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    s->channel_valid = TRUE;
 | 
			
		||||
    pa_dynarray_put((s->direction == PA_STREAM_RECORD) ? s->context->record_streams : s->context->playback_streams, s->channel, s);
 | 
			
		||||
    pa_hashmap_put((s->direction == PA_STREAM_RECORD) ? s->context->record_streams : s->context->playback_streams, PA_UINT32_TO_PTR(s->channel), s);
 | 
			
		||||
 | 
			
		||||
    create_stream_complete(s);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue