From a8a6def20fee7a3d5de09ab7e7688220c3d4a733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Sun, 23 May 2021 21:35:12 +0200 Subject: [PATCH] filter-chain: fix reference counting issue Fix a reference counting issue that resulted in ladspa_handle's refcount being equal to the sum of the refcounts of its descriptors. This would result in a memory leak when a descriptor is loaded more than once from the same handle. This cannot happen because `ladspa_handle_list` is not populated by `ladspa_handle_load()`. The next commit implements exactly that, so the fix is applied before the change that would introduce the problem. --- src/modules/module-filter-chain.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/modules/module-filter-chain.c b/src/modules/module-filter-chain.c index bb346b6d8..454b91073 100644 --- a/src/modules/module-filter-chain.c +++ b/src/modules/module-filter-chain.c @@ -844,6 +844,15 @@ static struct ladspa_descriptor *ladspa_descriptor_load(struct impl *impl, spa_list_for_each(desc, &hndl->descriptor_list, link) { if (spa_streq(desc->label, label)) { desc->ref++; + + /* + * since ladspa_handle_load() increments the reference count of the handle, + * if the descriptor is found, then the handle's reference count + * has already been incremented to account for the descriptor, + * so we need to unref handle here since we're merely reusing + * thedescriptor, not creating a new one + */ + ladspa_handle_unref(hndl); return desc; } }