mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	pipewire: module-profiler: handle global's destroy event
Handle if the global is destroyed (e.g. `pw-cli destroy X`) to avoid a use-after-free in `pw_global_destroy()` when it is called with a dangling pointer from `module_destroy()`.
This commit is contained in:
		
							parent
							
								
									336e4d5f03
								
							
						
					
					
						commit
						d4e4b5df98
					
				
					 1 changed files with 21 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -77,6 +77,7 @@ struct impl {
 | 
			
		|||
	struct spa_hook module_listener;
 | 
			
		||||
 | 
			
		||||
	struct pw_global *global;
 | 
			
		||||
	struct spa_hook global_listener;
 | 
			
		||||
 | 
			
		||||
	int64_t count;
 | 
			
		||||
	uint32_t busy;
 | 
			
		||||
| 
						 | 
				
			
			@ -338,7 +339,8 @@ static void module_destroy(void *data)
 | 
			
		|||
{
 | 
			
		||||
	struct impl *impl = data;
 | 
			
		||||
 | 
			
		||||
	pw_global_destroy(impl->global);
 | 
			
		||||
	if (impl->global != NULL)
 | 
			
		||||
		pw_global_destroy(impl->global);
 | 
			
		||||
 | 
			
		||||
	spa_hook_remove(&impl->module_listener);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -352,6 +354,22 @@ static const struct pw_impl_module_events module_events = {
 | 
			
		|||
	.destroy = module_destroy,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void global_destroy(void *data)
 | 
			
		||||
{
 | 
			
		||||
	struct impl *impl = data;
 | 
			
		||||
 | 
			
		||||
	stop_listener(impl);
 | 
			
		||||
	stop_flush(impl);
 | 
			
		||||
 | 
			
		||||
	spa_hook_remove(&impl->global_listener);
 | 
			
		||||
	impl->global = NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const struct pw_global_events global_events = {
 | 
			
		||||
	PW_VERSION_GLOBAL_EVENTS,
 | 
			
		||||
	.destroy = global_destroy,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
SPA_EXPORT
 | 
			
		||||
int pipewire__module_init(struct pw_impl_module *module, const char *args)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -398,5 +416,7 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
 | 
			
		|||
 | 
			
		||||
	pw_global_register(impl->global);
 | 
			
		||||
 | 
			
		||||
	pw_global_add_listener(impl->global, &impl->global_listener, &global_events, impl);
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue