FileSystem: Check PHYSFS_init() for success
Move it above the allocations so exceptions don't leak memory.
This commit is contained in:
		
							parent
							
								
									6fa5b8c856
								
							
						
					
					
						commit
						98bdfcf758
					
				
					 1 changed files with 11 additions and 2 deletions
				
			
		| 
						 | 
					@ -311,14 +311,23 @@ struct FileSystemPrivate
 | 
				
			||||||
	bool havePathCache;
 | 
						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,
 | 
					FileSystem::FileSystem(const char *argv0,
 | 
				
			||||||
                       bool allowSymlinks)
 | 
					                       bool allowSymlinks)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						if (PHYSFS_init(argv0) == 0)
 | 
				
			||||||
 | 
							throwPhysfsError("Error initializing PhysFS");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	p = new FileSystemPrivate;
 | 
						p = new FileSystemPrivate;
 | 
				
			||||||
	p->havePathCache = false;
 | 
						p->havePathCache = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	PHYSFS_init(argv0);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	PHYSFS_registerArchiver(&RGSS1_Archiver);
 | 
						PHYSFS_registerArchiver(&RGSS1_Archiver);
 | 
				
			||||||
	PHYSFS_registerArchiver(&RGSS2_Archiver);
 | 
						PHYSFS_registerArchiver(&RGSS2_Archiver);
 | 
				
			||||||
	PHYSFS_registerArchiver(&RGSS3_Archiver);
 | 
						PHYSFS_registerArchiver(&RGSS3_Archiver);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue