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:
Barnabás Pőcze 2022-09-03 02:43:51 +02:00 committed by Wim Taymans
parent 442a0c54ea
commit 086de7dcac

View file

@ -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) 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) 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) static int emit_object_info(struct impl *impl, struct device *device)