diff --git a/Core/Loaders.cpp b/Core/Loaders.cpp index f76ea3c6cc..3197a6dff2 100644 --- a/Core/Loaders.cpp +++ b/Core/Loaders.cpp @@ -388,14 +388,12 @@ bool UmdMount(const Path &filepath, FileLoader **fileLoader, std::string &error) delete loadedFile; return false; } - UpdateLoadedFile(loadedFile); - std::string errorString; IdentifiedFileType fileType; + // Can delete loadedFile and return another, or return a ZipFileLoader that owns it, so what it + // returns is what g_loadedFile owns. loadedFile = ResolveFileLoaderTarget(loadedFile, &fileType, &errorString); - *fileLoader = loadedFile; - switch (fileType) { case IdentifiedFileType::PSP_ISO: case IdentifiedFileType::PSP_ISO_NP: @@ -403,14 +401,21 @@ bool UmdMount(const Path &filepath, FileLoader **fileLoader, std::string &error) case IdentifiedFileType::PSP_UMD_VIDEO_ISO: if (!MountGameISO(loadedFile, &error)) { error = "mounting the ISO failed: " + error; + delete loadedFile; return false; } break; default: error = "Unsupported file type: " + std::string(IdentifiedFileTypeToString(fileType)) + " " + errorString; + delete loadedFile; return false; - break; } + + // Only now, with the old disc's file systems replaced, is the old loader unused: a swap that + // fails leaves the old disc mounted. Reads hold pspFileSystem's lock, which Mount takes, so none + // is still going on the IO thread either. + UpdateLoadedFile(loadedFile); + *fileLoader = loadedFile; return true; }