pipewire: improve memory cleanup

Add method to unload a spa interface.
Various other memory cleanups
This commit is contained in:
Wim Taymans 2018-04-20 16:27:19 +02:00
parent 0dc036ac84
commit d165b3b842
8 changed files with 362 additions and 80 deletions

View file

@ -200,6 +200,13 @@ static int make_link(struct impl *this,
return 0;
}
static void clean_link(struct impl *this, struct link *link)
{
if (link->buffers)
free(link->buffers);
link->buffers = NULL;
}
static int negotiate_link_format(struct impl *this, struct link *link)
{
struct type *t = &this->type;
@ -398,6 +405,8 @@ static int negotiate_link_buffers(struct impl *this, struct link *link)
aligns[i] = align;
}
if (link->buffers)
free(link->buffers);
link->buffers = spa_buffer_alloc_array(buffers, flags, 0, NULL, blocks, datas, aligns);
if (link->buffers == NULL)
return -ENOMEM;
@ -437,6 +446,13 @@ static int negotiate_link_buffers(struct impl *this, struct link *link)
return 0;
}
static void clean_buffers(struct impl *this)
{
int i;
for (i = 0; i < this->n_links; i++)
clean_link(this, &this->links[i]);
}
static int setup_buffers(struct impl *this, enum spa_direction direction)
{
int i, res;
@ -847,6 +863,13 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
static int impl_clear(struct spa_handle *handle)
{
struct impl *this;
spa_return_val_if_fail(handle != NULL, -EINVAL);
this = (struct impl *) handle;
clean_buffers(this);
return 0;
}

View file

@ -327,6 +327,8 @@ static int impl_clear(struct spa_handle *handle)
{
struct impl *this = (struct impl *) handle;
if (this->uitem.udevice)
udev_device_unref(this->uitem.udevice);
if (this->enumerate)
udev_enumerate_unref(this->enumerate);
if (this->umonitor)