Skip to content

[GEN][ZH] Fix various memory leaks #623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 9, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ ProductionUpdate::~ProductionUpdate( void )

production = m_productionQueue;
removeFromProductionQueue( production );
// TheSuperHackers @fix Mauller 13/04/2025 Delete instance of production item
production->deleteInstance();

} // end while

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ W3DLaserDraw::~W3DLaserDraw( void )
} // end for i

delete [] m_line3D;
// TheSuperHackers @fix Mauller 11/03/2025 Free reference counted material
REF_PTR_RELEASE(m_texture);
}

//-------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ void W3DTankDraw::createEmitters( void )
//-------------------------------------------------------------------------------------------------
W3DTankDraw::~W3DTankDraw()
{
// TheSuperHackers @fix Mauller 16/04/2025 Delete particle systems
tossEmitters();

for (Int i=0; i<MAX_TREADS_PER_TANK; i++)
if (m_treads[i].m_robj)
REF_PTR_RELEASE(m_treads[i].m_robj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,18 @@ W3DDisplay::~W3DDisplay()

// get rid of the debug display
delete m_debugDisplay;
m_debugDisplay = NULL;
m_nativeDebugDisplay = NULL;

// delete the display strings
for (int i = 0; i < DisplayStringCount; i++)
TheDisplayStringManager->freeDisplayString(m_displayStrings[i]);

// TheSuperHackers @fix Mauller/Tomsons26 28/04/2025 Free benchmark display string
if( m_benchmarkDisplayString ) {
TheDisplayStringManager->freeDisplayString(m_benchmarkDisplayString);
}

// delete 2D renderer
if( m_2DRender )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ ArchiveFile * Win32BIGFileSystem::openArchiveFile(const Char *filename) {
Int archiveFileSize = 0;
Int numLittleFiles = 0;

ArchiveFile *archiveFile = NEW Win32BIGFile;

DEBUG_LOG(("Win32BIGFileSystem::openArchiveFile - opening BIG file %s\n", filename));

if (fp == NULL) {
Expand Down Expand Up @@ -120,6 +118,8 @@ ArchiveFile * Win32BIGFileSystem::openArchiveFile(const Char *filename) {
fp->seek(0x10, File::START);
// read in each directory listing.
ArchivedFileInfo *fileInfo = NEW ArchivedFileInfo;
// TheSuperHackers @fix Mauller 23/04/2025 Create new file handle when necessary to prevent memory leak
ArchiveFile *archiveFile = NEW Win32BIGFile;

for (Int i = 0; i < numLittleFiles; ++i) {
Int filesize = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ Win32LocalFileSystem::~Win32LocalFileSystem() {
File * Win32LocalFileSystem::openFile(const Char *filename, Int access /* = 0 */)
{
//USE_PERF_TIMER(Win32LocalFileSystem_openFile)
Win32LocalFile *file = newInstance( Win32LocalFile );

// sanity check
if (strlen(filename) <= 0) {
Expand All @@ -69,6 +68,9 @@ File * Win32LocalFileSystem::openFile(const Char *filename, Int access /* = 0 */
}
}

// TheSuperHackers @fix Mauller 21/04/2025 Create new file handle when necessary to prevent memory leak
Win32LocalFile *file = newInstance( Win32LocalFile );

if (file->open(filename, access) == FALSE) {
file->close();
file->deleteInstance();
Expand Down
12 changes: 6 additions & 6 deletions Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ MeshModelClass::MeshModelClass(const MeshModelClass & that) :

MeshModelClass::~MeshModelClass(void)
{
// WWDEBUG_SAY(("Note: Mesh %s was never used\n",Get_Name()));
TheDX8MeshRenderer.Unregister_Mesh_Type(this);

Reset(0,0,0);
REF_PTR_RELEASE(MatInfo);
Expand Down Expand Up @@ -141,7 +139,7 @@ MeshModelClass & MeshModelClass::operator = (const MeshModelClass & that)
clone_materials(that);

if (GapFiller) {
delete[] GapFiller;
delete GapFiller;
GapFiller=NULL;
}
if (that.GapFiller) GapFiller=W3DNEW GapFillerClass(*that.GapFiller);
Expand All @@ -151,6 +149,11 @@ MeshModelClass & MeshModelClass::operator = (const MeshModelClass & that)

void MeshModelClass::Reset(int polycount,int vertcount,int passcount)
{
//DMS - We must delete the gapfiller object BEFORE the geometry is reset. Otherwise,
// the number of stages and passes gets reset and the gapfiller cannot deallocate properly.
delete GapFiller;
GapFiller=NULL;

Reset_Geometry(polycount,vertcount);

// Release everything we have and reset to initial state
Expand All @@ -165,9 +168,6 @@ void MeshModelClass::Reset(int polycount,int vertcount,int passcount)
}
CurMatDesc = DefMatDesc;

delete GapFiller;
GapFiller=NULL;

return ;
}

Expand Down
7 changes: 7 additions & 0 deletions GeneralsMD/Code/GameEngine/Source/GameClient/Snow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ SnowManager::~SnowManager()
{
delete [] m_startingHeights;
m_startingHeights=NULL;

// TheSuperHackers @fix Mauller 13/04/2025 Delete the instance of the weather settings
if (TheWeatherSetting)
{
((WeatherSetting*)TheWeatherSetting.getNonOverloadedPointer())->deleteInstance();
TheWeatherSetting=NULL;
}
}

OVERRIDE<WeatherSetting> TheWeatherSetting = NULL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ ProductionUpdate::~ProductionUpdate( void )

production = m_productionQueue;
removeFromProductionQueue( production );
// TheSuperHackers @fix Mauller 13/04/2025 Delete instance of production item
production->deleteInstance();

} // end while

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ W3DLaserDraw::~W3DLaserDraw( void )
} // end for i

delete [] m_line3D;
// TheSuperHackers @fix Mauller 11/03/2025 Free reference counted material
REF_PTR_RELEASE(m_texture);
}

//-------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ void W3DTankDraw::createEmitters( void )
//-------------------------------------------------------------------------------------------------
W3DTankDraw::~W3DTankDraw()
{
// TheSuperHackers @fix Mauller 16/04/2025 Delete particle systems
tossEmitters();

for (Int i=0; i<MAX_TREADS_PER_TANK; i++)
if (m_treads[i].m_robj)
REF_PTR_RELEASE(m_treads[i].m_robj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,18 @@ W3DDisplay::~W3DDisplay()

// get rid of the debug display
delete m_debugDisplay;
m_debugDisplay = NULL;
m_nativeDebugDisplay = NULL;

// delete the display strings
for (int i = 0; i < DisplayStringCount; i++)
TheDisplayStringManager->freeDisplayString(m_displayStrings[i]);

// TheSuperHackers @fix Mauller/Tomsons26 28/04/2025 Free benchmark display string
if( m_benchmarkDisplayString ) {
TheDisplayStringManager->freeDisplayString(m_benchmarkDisplayString);
}

// delete 2D renderer
if( m_2DRender )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ ArchiveFile * Win32BIGFileSystem::openArchiveFile(const Char *filename) {
Int archiveFileSize = 0;
Int numLittleFiles = 0;

ArchiveFile *archiveFile = NEW Win32BIGFile;

DEBUG_LOG(("Win32BIGFileSystem::openArchiveFile - opening BIG file %s\n", filename));

if (fp == NULL) {
Expand Down Expand Up @@ -133,6 +131,8 @@ ArchiveFile * Win32BIGFileSystem::openArchiveFile(const Char *filename) {
fp->seek(0x10, File::START);
// read in each directory listing.
ArchivedFileInfo *fileInfo = NEW ArchivedFileInfo;
// TheSuperHackers @fix Mauller 23/04/2025 Create new file handle when necessary to prevent memory leak
ArchiveFile *archiveFile = NEW Win32BIGFile;

for (Int i = 0; i < numLittleFiles; ++i) {
Int filesize = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ Win32LocalFileSystem::~Win32LocalFileSystem() {
File * Win32LocalFileSystem::openFile(const Char *filename, Int access /* = 0 */)
{
//USE_PERF_TIMER(Win32LocalFileSystem_openFile)
Win32LocalFile *file = newInstance( Win32LocalFile );

// sanity check
if (strlen(filename) <= 0) {
Expand All @@ -69,6 +68,9 @@ File * Win32LocalFileSystem::openFile(const Char *filename, Int access /* = 0 */
}
}

// TheSuperHackers @fix Mauller 21/04/2025 Create new file handle when necessary to prevent memory leak
Win32LocalFile *file = newInstance( Win32LocalFile );

if (file->open(filename, access) == FALSE) {
file->close();
file->deleteInstance();
Expand Down
2 changes: 0 additions & 2 deletions GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/meshmdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ MeshModelClass::MeshModelClass(const MeshModelClass & that) :

MeshModelClass::~MeshModelClass(void)
{
// WWDEBUG_SAY(("Note: Mesh %s was never used\n",Get_Name()));
TheDX8MeshRenderer.Unregister_Mesh_Type(this);

Reset(0,0,0);
REF_PTR_RELEASE(MatInfo);
Expand Down
Loading