greatest-ape / OctaSine

Frequency modulation synthesizer plugin (VST2, CLAP). Runs on macOS, Windows and Linux.
https://www.octasine.com/
GNU Affero General Public License v3.0
615 stars 16 forks source link

Possible memory leak(s) in CLAP plugin #187

Open messmerd opened 7 months ago

messmerd commented 7 months ago

Describe the bug The address sanitizer build of a CLAP host I'm developing indicates that there's a memory leak after I call the clap_plugin_factory->get_plugin_descriptor() function in the OctaSine v0.9 CLAP plugin.

I don't know Rust, so I couldn't tell if there were any ownership issues in src/plugin/clap/descriptor.rs or other files when I read them.

It's possible this could be a false positive from my address sanitizer, but none of the other CLAP plugins I've tested so far have had this issue.

What did you try to do Load the OctaSine v0.9.clap shared library in an address sanitizer build of a CLAP host, then step through the CLAP plugin initialization until it calls the clap_plugin_factory->get_plugin_descriptor() function. Skipping this function call avoids the memory leak message from the address sanitizer:

if (/*plugin is OctaSine*/) {
    static const clap_plugin_descriptor desc {
        clap_version{1, 0, 3},
        "OctaSine", // id
        "OctaSine", // name
        "Joakim Frostegard", // vendor
        "https://octasine.com", // url
        nullptr, // manual
        nullptr, // support
        "0.9.0", // version
        nullptr, // description
        (const char* const[]){ // features
            CLAP_PLUGIN_FEATURE_INSTRUMENT,
            CLAP_PLUGIN_FEATURE_SYNTHESIZER,
            CLAP_PLUGIN_FEATURE_STEREO,
            nullptr
        }
    };
    m_descriptor = &desc;
} else /*all other plugins*/ {
    m_descriptor = m_factory->get_plugin_descriptor(m_factory, m_index);
}

During plugin instantiation and usage, there appear to be additional memory leaks, but I haven't investigated them yet. The code above is enough to avoid the memory leak message during the initial scan: shared library loading + entry/init/get_factory + descriptor reading + deinit.

Expected behavior No memory leaks.

Screenshots N/A

Log file contents

I have address sanitizer output, but it probably won't be very useful, though it is apparently 6 bytes leaked.

Software:

Additional context N/A

greatest-ape commented 4 months ago

Thanks, I'll look into it.