mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	context: fix some memory leaks
This commit is contained in:
		
							parent
							
								
									1fd2e6beae
								
							
						
					
					
						commit
						6cd1104d0c
					
				
					 1 changed files with 21 additions and 12 deletions
				
			
		| 
						 | 
					@ -37,9 +37,20 @@ int pa_context_set_error(pa_context *c, int error) {
 | 
				
			||||||
	return error;
 | 
						return error;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void global_free(struct global *g)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						spa_list_remove(&g->link);
 | 
				
			||||||
 | 
						if (g->props)
 | 
				
			||||||
 | 
							pw_properties_free(g->props);
 | 
				
			||||||
 | 
						if (g->destroy)
 | 
				
			||||||
 | 
							g->destroy(g);
 | 
				
			||||||
 | 
						free(g);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void context_unlink(pa_context *c)
 | 
					static void context_unlink(pa_context *c)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	pa_stream *s, *t;
 | 
						pa_stream *s, *t;
 | 
				
			||||||
 | 
						struct global *g;
 | 
				
			||||||
	pa_operation *o;
 | 
						pa_operation *o;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pw_log_debug("context %p: unlink %d", c, c->state);
 | 
						pw_log_debug("context %p: unlink %d", c, c->state);
 | 
				
			||||||
| 
						 | 
					@ -48,6 +59,8 @@ static void context_unlink(pa_context *c)
 | 
				
			||||||
		pa_stream_set_state(s, c->state == PA_CONTEXT_FAILED ?
 | 
							pa_stream_set_state(s, c->state == PA_CONTEXT_FAILED ?
 | 
				
			||||||
				PA_STREAM_FAILED : PA_STREAM_TERMINATED);
 | 
									PA_STREAM_FAILED : PA_STREAM_TERMINATED);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						spa_list_consume(g, &c->globals, link)
 | 
				
			||||||
 | 
							global_free(g);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	spa_list_consume(o, &c->operations, link)
 | 
						spa_list_consume(o, &c->operations, link)
 | 
				
			||||||
		pa_operation_cancel(o);
 | 
							pa_operation_cancel(o);
 | 
				
			||||||
| 
						 | 
					@ -286,13 +299,14 @@ static void registry_event_global(void *data, uint32_t id, uint32_t parent_id,
 | 
				
			||||||
	g->parent_id = parent_id;
 | 
						g->parent_id = parent_id;
 | 
				
			||||||
	g->type = type;
 | 
						g->type = type;
 | 
				
			||||||
	g->props = props ? pw_properties_new_dict(props) : NULL;
 | 
						g->props = props ? pw_properties_new_dict(props) : NULL;
 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (set_mask(c, g) == 0)
 | 
					 | 
				
			||||||
		return;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	pw_log_debug("mask %d/%d", g->mask, g->event);
 | 
					 | 
				
			||||||
	spa_list_append(&c->globals, &g->link);
 | 
						spa_list_append(&c->globals, &g->link);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (set_mask(c, g) == 0) {
 | 
				
			||||||
 | 
							global_free(g);
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pw_log_debug("mask %d/%d", g->mask, g->event);
 | 
				
			||||||
	emit_event(c, g, PA_SUBSCRIPTION_EVENT_NEW);
 | 
						emit_event(c, g, PA_SUBSCRIPTION_EVENT_NEW);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -308,12 +322,7 @@ static void registry_event_global_remove(void *object, uint32_t id)
 | 
				
			||||||
	emit_event(c, g, PA_SUBSCRIPTION_EVENT_REMOVE);
 | 
						emit_event(c, g, PA_SUBSCRIPTION_EVENT_REMOVE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pw_log_debug("context %p: free %d %p", c, id, g);
 | 
						pw_log_debug("context %p: free %d %p", c, id, g);
 | 
				
			||||||
	spa_list_remove(&g->link);
 | 
						global_free(g);
 | 
				
			||||||
	if (g->props)
 | 
					 | 
				
			||||||
		pw_properties_free(g->props);
 | 
					 | 
				
			||||||
	if (g->destroy)
 | 
					 | 
				
			||||||
		g->destroy(g);
 | 
					 | 
				
			||||||
	free(g);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const struct pw_registry_proxy_events registry_events =
 | 
					static const struct pw_registry_proxy_events registry_events =
 | 
				
			||||||
| 
						 | 
					@ -471,7 +480,7 @@ static void context_free(pa_context *c)
 | 
				
			||||||
	if (c->core_info)
 | 
						if (c->core_info)
 | 
				
			||||||
		pw_core_info_free(c->core_info);
 | 
							pw_core_info_free(c->core_info);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pw_remote_destroy(c->remote);
 | 
						pw_core_destroy(c->core);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void pa_context_unref(pa_context *c)
 | 
					void pa_context_unref(pa_context *c)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue