From 98bdfcf7585ef3b3fcd4377a6d63b3f77cb6a33b Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Sat, 18 May 2019 16:22:53 +0200 Subject: [PATCH] FileSystem: Check PHYSFS_init() for success Move it above the allocations so exceptions don't leak memory. --- src/filesystem.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/filesystem.cpp b/src/filesystem.cpp index b898daa..f448ac5 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -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);