Skip to content

Commit 3b9c233

Browse files
committed
[GEN][ZH] Fix Win32LocalFileSystem leaking file handlers when returning early on null filenames (#623)
1 parent 95ab8ab commit 3b9c233

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Generals/Code/GameEngineDevice/Source/Win32Device/Common/Win32LocalFileSystem.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ Win32LocalFileSystem::~Win32LocalFileSystem() {
4545
File * Win32LocalFileSystem::openFile(const Char *filename, Int access /* = 0 */)
4646
{
4747
//USE_PERF_TIMER(Win32LocalFileSystem_openFile)
48-
Win32LocalFile *file = newInstance( Win32LocalFile );
4948

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

71+
// TheSuperHackers Mauller 21/04/2025 Only create the new file instance when it is necassary or we leak file handles!
72+
Win32LocalFile *file = newInstance( Win32LocalFile );
73+
7274
if (file->open(filename, access) == FALSE) {
7375
file->close();
7476
file->deleteInstance();

GeneralsMD/Code/GameEngineDevice/Source/Win32Device/Common/Win32LocalFileSystem.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ Win32LocalFileSystem::~Win32LocalFileSystem() {
4545
File * Win32LocalFileSystem::openFile(const Char *filename, Int access /* = 0 */)
4646
{
4747
//USE_PERF_TIMER(Win32LocalFileSystem_openFile)
48-
Win32LocalFile *file = newInstance( Win32LocalFile );
4948

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

71+
// TheSuperHackers Mauller 21/04/2025 Only create the new file instance when it is necassary or we leak file handles!
72+
Win32LocalFile *file = newInstance( Win32LocalFile );
73+
7274
if (file->open(filename, access) == FALSE) {
7375
file->close();
7476
file->deleteInstance();

0 commit comments

Comments
 (0)