From 5e33107e8683c35bbe1417406eb34aadfad19ba4 Mon Sep 17 00:00:00 2001 From: Mauller <26652186+Mauller@users.noreply.github.com> Date: Mon, 7 Apr 2025 21:48:08 +0100 Subject: [PATCH 1/8] [GEN][ZH] Fix material memory leak in ~W3DLaserDraw() (#623) --- .../Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp | 2 ++ .../Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp index 8f983f1a9e..03c2c710ad 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp @@ -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); } //------------------------------------------------------------------------------------------------- diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp index ec8dec496e..31ef5c6582 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DLaserDraw.cpp @@ -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); } //------------------------------------------------------------------------------------------------- From fda7c138200eecf6d9d36959426929e809079377 Mon Sep 17 00:00:00 2001 From: Mauller <26652186+Mauller@users.noreply.github.com> Date: Sun, 13 Apr 2025 16:50:23 +0100 Subject: [PATCH 2/8] [GEN][ZH] Fix production queue items memory leak in ~ProductionUpdate() (#623) --- .../Source/GameLogic/Object/Update/ProductionUpdate.cpp | 2 ++ .../Source/GameLogic/Object/Update/ProductionUpdate.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp index d9ce37a45d..56fc57d9aa 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp @@ -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 diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp index 8ee4716c02..662d651266 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/ProductionUpdate.cpp @@ -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 From cf32f8d761cb113b17e3b4041cb93f611be03609 Mon Sep 17 00:00:00 2001 From: Mauller <26652186+Mauller@users.noreply.github.com> Date: Sun, 13 Apr 2025 16:51:24 +0100 Subject: [PATCH 3/8] [ZH] Fix weather settings memory leak in ~SnowManager() (#623) --- GeneralsMD/Code/GameEngine/Source/GameClient/Snow.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Snow.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Snow.cpp index dd926de453..e2617586b6 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/Snow.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Snow.cpp @@ -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 TheWeatherSetting = NULL; From 322fca6a3dfae9ab16a901100b9f181d70b74e71 Mon Sep 17 00:00:00 2001 From: Mauller <26652186+Mauller@users.noreply.github.com> Date: Wed, 16 Apr 2025 17:32:13 +0100 Subject: [PATCH 4/8] [GEN][ZH] Fix particle systems memory leak in ~W3DTankDraw() (#623) --- .../Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp | 3 +++ .../Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp index 8c178eb322..c409c8610d 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/Drawable/Draw/W3DTankDraw.cpp @@ -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 Date: Mon, 21 Apr 2025 10:01:17 +0100 Subject: [PATCH 5/8] [GEN][ZH] Fix FileSystems memory leak on null filenames (#623) --- .../Source/Win32Device/Common/Win32BIGFileSystem.cpp | 4 ++-- .../Source/Win32Device/Common/Win32LocalFileSystem.cpp | 4 +++- .../Source/Win32Device/Common/Win32BIGFileSystem.cpp | 4 ++-- .../Source/Win32Device/Common/Win32LocalFileSystem.cpp | 4 +++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Generals/Code/GameEngineDevice/Source/Win32Device/Common/Win32BIGFileSystem.cpp b/Generals/Code/GameEngineDevice/Source/Win32Device/Common/Win32BIGFileSystem.cpp index 11ebc499a3..94730ba482 100644 --- a/Generals/Code/GameEngineDevice/Source/Win32Device/Common/Win32BIGFileSystem.cpp +++ b/Generals/Code/GameEngineDevice/Source/Win32Device/Common/Win32BIGFileSystem.cpp @@ -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) { @@ -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; diff --git a/Generals/Code/GameEngineDevice/Source/Win32Device/Common/Win32LocalFileSystem.cpp b/Generals/Code/GameEngineDevice/Source/Win32Device/Common/Win32LocalFileSystem.cpp index 80cfd4611d..08a5eaaaee 100644 --- a/Generals/Code/GameEngineDevice/Source/Win32Device/Common/Win32LocalFileSystem.cpp +++ b/Generals/Code/GameEngineDevice/Source/Win32Device/Common/Win32LocalFileSystem.cpp @@ -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) { @@ -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(); diff --git a/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/Common/Win32BIGFileSystem.cpp b/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/Common/Win32BIGFileSystem.cpp index e9c0bc91e2..8ba95f2adb 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/Common/Win32BIGFileSystem.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/Common/Win32BIGFileSystem.cpp @@ -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) { @@ -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; diff --git a/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/Common/Win32LocalFileSystem.cpp b/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/Common/Win32LocalFileSystem.cpp index 19b78e8770..e1f00f7334 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/Common/Win32LocalFileSystem.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/Common/Win32LocalFileSystem.cpp @@ -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) { @@ -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(); From bee9907575829d2f9265647e8e27661b87c6d11d Mon Sep 17 00:00:00 2001 From: Mauller <26652186+Mauller@users.noreply.github.com> Date: Mon, 21 Apr 2025 20:07:59 +0100 Subject: [PATCH 6/8] [GEN] Fix wrong delete function usage in ~MeshModelClass() (#623) --- Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdl.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdl.cpp index bc96aec7c5..a5b0babf7a 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdl.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdl.cpp @@ -141,7 +141,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); From 7c51a0146053f6b03191cfb6524094fa58a0e2c0 Mon Sep 17 00:00:00 2001 From: Mauller <26652186+Mauller@users.noreply.github.com> Date: Sun, 20 Apr 2025 10:35:04 +0100 Subject: [PATCH 7/8] [GEN][ZH] Remove redundant mesh unregister call in ~MeshModelClass() (#623) --- .../Code/Libraries/Source/WWVegas/WW3D2/meshmdl.cpp | 10 +++++----- .../Code/Libraries/Source/WWVegas/WW3D2/meshmdl.cpp | 2 -- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdl.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdl.cpp index a5b0babf7a..49d1bdc338 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdl.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/meshmdl.cpp @@ -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); @@ -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 @@ -165,9 +168,6 @@ void MeshModelClass::Reset(int polycount,int vertcount,int passcount) } CurMatDesc = DefMatDesc; - delete GapFiller; - GapFiller=NULL; - return ; } diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/meshmdl.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/meshmdl.cpp index 531552433c..5d8b9876b0 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/meshmdl.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/meshmdl.cpp @@ -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); From f5f0f26f9a59d00ec70e6f0e7d7c1e4bafa08593 Mon Sep 17 00:00:00 2001 From: Mauller <26652186+Mauller@users.noreply.github.com> Date: Mon, 28 Apr 2025 21:29:54 +0100 Subject: [PATCH 8/8] [GEN][ZH] Fix DisplayString memory leak in ~W3DDisplay() (#623) --- .../Source/W3DDevice/GameClient/W3DDisplay.cpp | 7 +++++++ .../Source/W3DDevice/GameClient/W3DDisplay.cpp | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp index 9f582cccc5..1bbbaa080b 100644 --- a/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp +++ b/Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp @@ -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 ) { diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp index 57d2450c21..7b5a8bddc7 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp @@ -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 ) {