[Bug]: LV2 host leaks the scale point collection of every port (lilv_port_get_scale_points never freed)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- cpp
- Domain
- audio-video-rtc, backend
Research direction
Start in juce_LV2PluginFormatImpl.h at ScalePoints and Port::getScalePoints(), then trace how ParameterInfo::getScalePoints() reads the collection. The issue includes a LeakSanitizer reproduction using an LV2 plug-in with scale points; run it with leak detection enabled and confirm the collection is freed after port information is read.
Written by the indexing model from the issue text.
Description
Detailed steps on how to reproduce the bug
lv2_host::Port::getScalePoints() wraps the result of lilv_port_get_scale_points() in lv2_host::ScalePoints, which stores it as a raw const LilvScalePoints* and never frees it. lilv documents that the returned collection "must be freed by caller with lilv_scale_points_free()" (lilv.h, lilv_port_get_scale_points).
ParameterInfo::getScalePoints() calls this for every port while a plug-in instance is created (Ports::getPorts → ParameterInfo::getInfoForPort), so each instance of a plug-in with enumerated ports leaks one collection per such port.
Repro: build a host with AddressSanitizer (leak detection on), instantiate an LV2 plug-in that has ports with scale points (we see it with sfizz.lv2), quit. LeakSanitizer reports e.g. "1913 byte(s) leaked in 72 allocation(s)" with this path:
#1 zix_tree_new lilv/src/zix/tree.c:74
#2 lilv_collection_new lilv/src/collections.c:52
#3 lilv_scale_points_new lilv/src/collections.c:88
#4 lilv_port_get_scale_points lilv/src/port.c:242
#5 juce::lv2_host::Port::getScalePoints() const juce_LV2PluginFormatImpl.h:526
#6 juce::lv2_host::ParameterInfo::getScalePoints(juce::lv2_host::Port const&) juce_LV2PluginFormatImpl.h:1593
#7 juce::lv2_host::ParameterInfo::getInfoForPort(...) juce_LV2PluginFormatImpl.h:1610
#8 juce::lv2_host::Ports::getPorts(...) juce_LV2PluginFormatImpl.h:1951
#9 juce::LV2PluginFormatHeadless::Pimpl::createPluginInstance<...>(...) juce_LV2PluginFormatImpl.h:4466
How we use it: our app (a looper built on a Giada fork) hosts sfizz and DrumGizmo through JUCE's LV2 host and runs its app tests under ASan; this leak was the only one left in our code paths. JUCE 9.0.4; the same code is on develop today.
The fix we carry: let ScalePoints own the collection.
@@ -413,19 +413,25 @@ using NonOwningNodes = NodesImpl<NonOwningPtrTraits<LilvNodes>>;
class ScalePoints
{
public:
- explicit ScalePoints (const LilvScalePoints* pt)
+ // lilv_port_get_scale_points returns a collection the caller must free.
+ explicit ScalePoints (LilvScalePoints* pt)
: points (pt) {}
ScalePointsIterator begin() const noexcept
{
return points == nullptr ? ScalePointsIterator{}
- : ScalePointsIterator { points };
+ : ScalePointsIterator { points.get() };
}
ScalePointsIterator end() const noexcept { return {}; }
private:
- const LilvScalePoints* points = nullptr;
+ struct Free
+ {
+ void operator() (LilvScalePoints* ptr) const noexcept { lilv_scale_points_free (ptr); }
+ };
+
+ std::unique_ptr<LilvScalePoints, Free> points;
};
class ScalePoint
What is the expected behaviour?
The scale point collection is freed after the port's info has been read (no LeakSanitizer report).
Operating systems
Linux
What versions of the operating systems?
Arch Linux (Omarchy), kernel 7.2, GCC 16
Architectures
x86_64
Plug-in formats (if applicable)
LV2
Testing on the develop branch
The bug is present on the develop branch (same ScalePoints class, checked today).
- Dominant language
- C++
- Stars
- 8.9k
- Forks
- 2.2k
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from juce-framework/JUCE
-
[Bug]: VST3 getMidiControllerAssignment reads past midiControllerToParameter for program changeOpen
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
juce-framework/JUCE#1810 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
juce-framework/JUCE#1805 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
juce-framework/JUCE#1804 ·
-
[Bug]: Linux: an embedded window's vblank rate comes from the display at its parent-relative boundsOpen
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
juce-framework/JUCE#1800 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
juce-framework/JUCE#1795 ·
All issues in juce-framework/JUCE
Similar issues
-
ai_p2
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
ClickHouse/ClickHouse#132519 ·
Maintainers usually reply within 1 day
-
patch_advisor_json_integration fails when the build tree is reached through a symbolic linkPossibly taken @DerKarussellbremser claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
boykopovar/AnyPS5#22581 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 82/100
petercorke/robotics-toolbox-python#952 ·
Maintainers usually reply within 1 day
-
NatronRenderer: a Python error in the script (-t / project script) doesn't change the exit statusOpenfunc:engine type:bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
NatronGitHub/Natron#1276 ·
Maintainers usually reply within 1 day