FileSystem: Check PHYSFS_init() for success

Move it above the allocations so exceptions don't leak memory.
This commit is contained in:
Jonas Kulla 2019-05-18 16:22:53 +02:00
parent 6fa5b8c856
commit 98bdfcf758
1 changed files with 11 additions and 2 deletions

View File

@ -311,14 +311,23 @@ struct FileSystemPrivate
bool havePathCache;
};
static void throwPhysfsError(const char *desc)
{
PHYSFS_ErrorCode ec = PHYSFS_getLastErrorCode();
const char *englishStr = PHYSFS_getErrorByCode(ec);
throw Exception(Exception::PHYSFSError, "%s: %s", desc, englishStr);
}
FileSystem::FileSystem(const char *argv0,
bool allowSymlinks)
{
if (PHYSFS_init(argv0) == 0)
throwPhysfsError("Error initializing PhysFS");
p = new FileSystemPrivate;
p->havePathCache = false;
PHYSFS_init(argv0);
PHYSFS_registerArchiver(&RGSS1_Archiver);
PHYSFS_registerArchiver(&RGSS2_Archiver);
PHYSFS_registerArchiver(&RGSS3_Archiver);