From 80cf20a255d17bfb69ddc5d7d9306477fed539ac Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 22 Aug 2017 19:22:04 +0200 Subject: [PATCH] monitor: fix some leaks --- spa/plugins/alsa/alsa-monitor.c | 21 ++++++++++++++++++--- spa/plugins/v4l2/v4l2-monitor.c | 19 ++++++++++++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/spa/plugins/alsa/alsa-monitor.c b/spa/plugins/alsa/alsa-monitor.c index f927d2e89..a64a7a649 100644 --- a/spa/plugins/alsa/alsa-monitor.c +++ b/spa/plugins/alsa/alsa-monitor.c @@ -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) diff --git a/spa/plugins/v4l2/v4l2-monitor.c b/spa/plugins/v4l2/v4l2-monitor.c index b266da04a..8f756c3f6 100644 --- a/spa/plugins/v4l2/v4l2-monitor.c +++ b/spa/plugins/v4l2/v4l2-monitor.c @@ -252,14 +252,16 @@ 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, "video4linux", NULL); - udev_monitor_enable_receiving(this->umonitor); + this->source.func = impl_on_fd_events; this->source.data = this; this->source.fd = udev_monitor_get_fd(this->umonitor);; @@ -348,6 +350,15 @@ 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->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; } @@ -365,7 +376,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)