mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	spa: libcamera: properly dispose of shared_ptr
Previously, in `remove_device()`, the last device would be copied into the slot of the to-be-remove device. The problem with this is that it left the shared_ptr untouched in the previously last slot, and hence creating an extra reference. Fix this by moving instead of copying. A similar problem is present in `clear_devices()` which also did not properly dispose of the shared_ptrs. Fix that by calling `reset()` on each device's camera pointer.
This commit is contained in:
		
							parent
							
								
									442a0c54ea
								
							
						
					
					
						commit
						086de7dcac
					
				
					 1 changed files with 4 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -143,12 +143,14 @@ static struct device *find_device(struct impl *impl, const Camera *camera)
 | 
			
		|||
 | 
			
		||||
static void remove_device(struct impl *impl, struct device *device)
 | 
			
		||||
{
 | 
			
		||||
	*device = impl->devices[--impl->n_devices];
 | 
			
		||||
	device->camera.reset();
 | 
			
		||||
	*device = std::move(impl->devices[--impl->n_devices]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void clear_devices(struct impl *impl)
 | 
			
		||||
{
 | 
			
		||||
	impl->n_devices = 0;
 | 
			
		||||
	while (impl->n_devices > 0)
 | 
			
		||||
		impl->devices[--impl->n_devices].camera.reset();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int emit_object_info(struct impl *impl, struct device *device)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue