monitor: fix some leaks

This commit is contained in:
Wim Taymans 2017-08-22 19:22:04 +02:00
parent c25834a692
commit 80cf20a255
2 changed files with 34 additions and 6 deletions

View file

@ -374,12 +374,13 @@ impl_monitor_set_callbacks(struct spa_monitor *monitor,
if ((res = impl_udev_open(this)) < 0)
return res;
if (this->umonitor)
udev_monitor_unref(this->umonitor);
this->umonitor = udev_monitor_new_from_netlink(this->udev, "udev");
if (!this->umonitor)
if (this->umonitor == NULL)
return SPA_RESULT_ERROR;
udev_monitor_filter_add_match_subsystem_devtype(this->umonitor, "sound", NULL);
udev_monitor_enable_receiving(this->umonitor);
this->source.func = impl_on_fd_events;
@ -441,6 +442,7 @@ static int impl_monitor_enum_items(struct spa_monitor *monitor,
}
}
if (get_next_device(this, this->dev) < 0) {
udev_device_unref(this->dev);
close_card(this);
goto next;
}
@ -478,6 +480,17 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
static int impl_clear(struct spa_handle *handle)
{
struct impl *this = (struct impl *) handle;
if (this->dev)
udev_device_unref(this->dev);
if (this->enumerate)
udev_enumerate_unref(this->enumerate);
if (this->umonitor)
udev_monitor_unref(this->umonitor);
if (this->udev)
udev_unref(this->udev);
return SPA_RESULT_OK;
}
@ -495,7 +508,9 @@ impl_init(const struct spa_handle_factory *factory,
spa_return_val_if_fail(handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
handle->get_interface = impl_get_interface;
handle->clear = impl_clear, this = (struct impl *) handle;
handle->clear = impl_clear;
this = (struct impl *) handle;
for (i = 0; i < n_support; i++) {
if (strcmp(support[i].type, SPA_TYPE__TypeMap) == 0)