From d9835cb2b43dbd9c216679b0c1d0808987d604b3 Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Thu, 23 Nov 2023 21:24:22 -0500 Subject: [PATCH] Revert SetMaxLength() change and instead call TakeDataOwnership() to fix memory leak in InitSaveProfile() --- neo/sys/sys_profile.cpp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/neo/sys/sys_profile.cpp b/neo/sys/sys_profile.cpp index c4c655b9..ab48ca6d 100644 --- a/neo/sys/sys_profile.cpp +++ b/neo/sys/sys_profile.cpp @@ -342,15 +342,7 @@ 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(); - // 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 ); + profileFile->SetMaxLength( MAX_PROFILE_SIZE ); // 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) @@ -368,7 +360,7 @@ bool idSaveGameProcessorSaveProfile::InitSaveProfile( idPlayerProfile* profile_, // Add data to the file and prepare for save profileFile->Write( msg.GetReadData(), msg.GetSize() ); - profileFile->MakeReadOnly(); + profileFile->TakeDataOwnership(); // SRS - this makes the file read-only and enables data buffer release saveFileEntryList_t files; files.Append( profileFile );