Fix a bunch of memory leaks throughout codebase

This commit is contained in:
Stephen Saunders 2023-11-15 13:22:04 -05:00 committed by Robert Beckebans
parent 92ad0cb0fe
commit fe411ba3b5
10 changed files with 23 additions and 1 deletions

View file

@ -3558,11 +3558,15 @@ cm_model_t* idCollisionModelManagerLocal::LoadBinaryModelFromFile( idFile* file,
}
file->ReadBig( model->polygonMemory );
// SRS - Boost polygonMemory to handle in-memory (ptr) vs. on-disk (int) size for cm_polygon_t.material, otherwise AllocPolygon() leaks
model->polygonMemory += ( sizeof( idMaterial* ) - sizeof( int ) ) * model->numPolygons;
model->polygonBlock = ( cm_polygonBlock_t* ) Mem_ClearedAlloc( sizeof( cm_polygonBlock_t ) + model->polygonMemory, TAG_COLLISION );
model->polygonBlock->bytesRemaining = model->polygonMemory;
model->polygonBlock->next = ( ( byte* ) model->polygonBlock ) + sizeof( cm_polygonBlock_t );
file->ReadBig( model->brushMemory );
// SRS - Boost brushMemory to handle in-memory (ptr) vs. on-disk (int) size for cm_brush_t.material, otherwise AllocBrush() leaks
model->brushMemory += ( sizeof( idMaterial* ) - sizeof( int ) ) * model->numBrushes;
model->brushBlock = ( cm_brushBlock_t* ) Mem_ClearedAlloc( sizeof( cm_brushBlock_t ) + model->brushMemory, TAG_COLLISION );
model->brushBlock->bytesRemaining = model->brushMemory;
model->brushBlock->next = ( ( byte* ) model->brushBlock ) + sizeof( cm_brushBlock_t );

View file

@ -920,6 +920,7 @@ void idCommonLocal::RenderBink( const char* path )
materialText.Format( "{ translucent { videoMap %s } }", path );
idMaterial* material = const_cast<idMaterial*>( declManager->FindMaterial( "splashbink" ) );
material->FreeData(); // SRS - always free data before parsing, otherwise leaks occur
material->Parse( materialText.c_str(), materialText.Length(), false );
material->ResetCinematicTime( Sys_Milliseconds() );

View file

@ -2881,6 +2881,7 @@ int idFileSystemLocal::AddResourceFile( const char* resourceFileName )
common->Printf( "Loaded resource file %s\n", resourceFile.c_str() );
return resourceFiles.Num() - 1;
}
delete rc;
return -1;
}

View file

@ -231,6 +231,7 @@ void idPolynomial::Test()
value = p.GetValue( roots[i] );
assert( idMath::Fabs( value ) < 1e-4f );
}
Mem_Free16( p.coefficient );
p = idPolynomial( -5.0f, 4.0f, 3.0f );
num = p.GetRoots( roots );
@ -239,6 +240,7 @@ void idPolynomial::Test()
value = p.GetValue( roots[i] );
assert( idMath::Fabs( value ) < 1e-4f );
}
Mem_Free16( p.coefficient );
p = idPolynomial( 1.0f, 4.0f, 3.0f, -2.0f );
num = p.GetRoots( roots );
@ -247,6 +249,7 @@ void idPolynomial::Test()
value = p.GetValue( roots[i] );
assert( idMath::Fabs( value ) < 1e-4f );
}
Mem_Free16( p.coefficient );
p = idPolynomial( 5.0f, 4.0f, 3.0f, -2.0f );
num = p.GetRoots( roots );
@ -255,6 +258,7 @@ void idPolynomial::Test()
value = p.GetValue( roots[i] );
assert( idMath::Fabs( value ) < 1e-4f );
}
Mem_Free16( p.coefficient );
p = idPolynomial( -5.0f, 4.0f, 3.0f, 2.0f, 1.0f );
num = p.GetRoots( roots );
@ -263,6 +267,7 @@ void idPolynomial::Test()
value = p.GetValue( roots[i] );
assert( idMath::Fabs( value ) < 1e-4f );
}
Mem_Free16( p.coefficient );
p = idPolynomial( 1.0f, 4.0f, 3.0f, -2.0f );
num = p.GetRoots( complexRoots );
@ -271,6 +276,7 @@ void idPolynomial::Test()
complexValue = p.GetValue( complexRoots[i] );
assert( idMath::Fabs( complexValue.r ) < 1e-4f && idMath::Fabs( complexValue.i ) < 1e-4f );
}
Mem_Free16( p.coefficient );
p = idPolynomial( 5.0f, 4.0f, 3.0f, -2.0f );
num = p.GetRoots( complexRoots );
@ -279,4 +285,5 @@ void idPolynomial::Test()
complexValue = p.GetValue( complexRoots[i] );
assert( idMath::Fabs( complexValue.r ) < 1e-4f && idMath::Fabs( complexValue.i ) < 1e-4f );
}
Mem_Free16( p.coefficient );
}

View file

@ -190,6 +190,8 @@ ID_INLINE idPolynomial idPolynomial::operator-() const
ID_INLINE idPolynomial& idPolynomial::operator=( const idPolynomial& p )
{
allocated = p.allocated;
coefficient = p.coefficient;
Resize( p.degree, false );
for( int i = 0; i <= degree; i++ )
{

View file

@ -175,6 +175,8 @@ BinkDecoder::~BinkDecoder()
delete[] planes[i].last;
}
FreeBundles();
for (uint32_t i = 0; i < audioTracks.size(); i++)
{
delete[] audioTracks[i]->buffer;

View file

@ -160,6 +160,9 @@ void idRenderProgManager::LoadShader( shader_t& shader )
( constants.Num() > 0 ) ? &constants[0] : shaderConstant, uint32_t( constants.Num() ) );
shader.handle = shaderHandle;
// SRS - Free the shader blob data, otherwise a leak will occur
Mem_Free( shaderBlob.data );
}
/*

View file

@ -525,6 +525,7 @@ int idSaveGameThread::Enumerate()
// DG: just use the idFile object's timestamp - the windows code gets file attributes and
// other complicated stuff like that.. I'm wonderin what that was good for.. this seems to work.
details->date = file->Timestamp();
delete file;
#endif // DG end
}
else

View file

@ -1021,6 +1021,7 @@ void Sys_InitNetworking()
// DG end
num_interfaces++;
}
free( ifap );
#else // not _WIN32, OSX or FreeBSD
int s;
char buf[ MAX_INTERFACES * sizeof( ifreq ) ];

View file

@ -100,7 +100,7 @@ const char* Sys_DefaultSavePath()
char* base_path = SDL_GetPrefPath( "", "RBDOOM-3-BFG" );
if( base_path )
{
savepath = SDL_strdup( base_path );
savepath = base_path;
savepath.StripTrailing( '/' );
SDL_free( base_path );
}