Scanning plugins timer re-entrancy


#1

I’ve been investigating a heap corruption when scanning certain plugins and it looks like what is happening is that during the initialisation (e.g. VSTPluginInstance::constructEffect), they’re doing something to dispatch the message loop.

This means that the PluginListComponent::timerCallback gets called again even though it is already sitting in it which leads to starting a new scan during construction of the old one and hence the world implodes…

I think a simple re-entrancy check could help here and I don’t think this would affect things if the scan is happening on multiple threads…
juce_scanning.patch (970 Bytes)

Is this a logical addition?


#2

Looks like there is a slight issue with this.
If the scan finishes, finishedScan() will get called which will delete the scanner.
When the local ScopedValueSetter then goes out of scope, it tries to set the now-deleted timerReentrancyCheck member back to what it was. ASan will trigger on this.

I think this should work:

    void timerCallback() override
    {
        if (timerReentrancyCheck)
            return;

        if (pool == nullptr)
        {
            const ScopedValueSetter<bool> setter (timerReentrancyCheck, true);
            
            if (doNextScan())
                startTimer (20);
        }

        if (! progressWindow.isCurrentlyModal())
            finished = true;

        if (finished)
            finishedScan();
        else
            progressWindow.setMessage (TRANS("Testing") + ":\n\n" + pluginBeingScanned);
    }