mirror of
https://github.com/id-Software/DOOM-3-BFG.git
synced 2025-04-24 02:32:18 +00:00
Fix a leak in InitSaveProfile() caused by skipping file memory cleanup in ~idFile_Memory() when maxSize != 0
This commit is contained in:
parent
04c638fb28
commit
402496411b
1 changed files with 9 additions and 1 deletions
|
@ -342,7 +342,15 @@ bool idSaveGameProcessorSaveProfile::InitSaveProfile( idPlayerProfile* profile_,
|
|||
// Serialize the profile and pass a file to the processor
|
||||
profileFile = new( TAG_SAVEGAMES ) idFile_SaveGame( SAVEGAME_PROFILE_FILENAME, SAVEGAMEFILE_BINARY | SAVEGAMEFILE_AUTO_DELETE );
|
||||
profileFile->MakeWritable();
|
||||
profileFile->SetMaxLength( MAX_PROFILE_SIZE );
|
||||
// SRS - Use SetLength()/TruncateData() vs. SetMaxLength() to avoid setting maxSize to non-zero value
|
||||
// - maxSize seems to have overloaded semantics that implies an externally-managed buffer: see
|
||||
// a) idFile_Memory::idFile_Memory( const char* name, char* data, int length ), and
|
||||
// b) idFile_Memory::~idFile_Memory()
|
||||
// - This change avoids a leak caused by skipping internally-managed file memory cleanup in the
|
||||
// idFile_Memory::~idFile_Memory() destructor (on write completion) when maxSize is non-zero
|
||||
// - Note the serializer already enforces MAX_PROFILE_SIZE so file system enforcement not needed
|
||||
profileFile->SetLength( MAX_PROFILE_SIZE );
|
||||
profileFile->TruncateData( 0 );
|
||||
|
||||
// Create a serialization object and let the game serialize the settings into the buffer
|
||||
const int serializeSize = MAX_PROFILE_SIZE - 8; // -8 for checksum (all platforms) and length (on 360)
|
||||
|
|
Loading…
Reference in a new issue