1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

AU Host: Avoid using wrong BundleResourceMap when opening plugin from file

Previously it was possible to have a dangling resource map. In that case
opening an AU from a file that did not have a resource map would lead to
using the previously unclosed map and attempting to load the previous
plugin again.
This commit is contained in:
attila 2022-03-22 11:20:52 +01:00 committed by Attila Szarvas
parent 55b00fc846
commit 5343f70d02

View file

@ -216,13 +216,40 @@ namespace AudioUnitFormatHelpers
if (manuString != nullptr && CFGetTypeID (manuString) == CFStringGetTypeID())
manufacturer = String::fromCFString ((CFStringRef) manuString);
const ResFileRefNum resFileId = CFBundleOpenBundleResourceMap (bundleRef.get());
UseResFile (resFileId);
class ScopedBundleResourceMap final
{
public:
explicit ScopedBundleResourceMap (CFBundleRef refIn) : ref (refIn),
resFileId (CFBundleOpenBundleResourceMap (ref)),
valid (resFileId != -1)
{
if (valid)
UseResFile (resFileId);
}
~ScopedBundleResourceMap()
{
if (valid)
CFBundleCloseBundleResourceMap (ref, resFileId);
}
bool isValid() const noexcept
{
return valid;
}
private:
const CFBundleRef ref;
const ResFileRefNum resFileId;
const bool valid;
};
const ScopedBundleResourceMap resourceMap { bundleRef.get() };
const OSType thngType = stringToOSType ("thng");
auto numResources = Count1Resources (thngType);
if (numResources > 0)
if (resourceMap.isValid() && numResources > 0)
{
for (ResourceIndex i = 1; i <= numResources; ++i)
{
@ -268,8 +295,6 @@ namespace AudioUnitFormatHelpers
[bundle release];
}
CFBundleCloseBundleResourceMap (bundleRef.get(), resFileId);
}
}