Fix fd memory leak on Linux (#264)

The Linux implementation of `OS_fopen` fails to close directories after
use, leaking the underlying file descriptors. Eventually, the limit of
allowed file descriptors per process is reached, causing subsequent
`opendir` failures, and leading to random game crashes.

Fix this issue by calling `closedir` once the directory can be disposed.

Signed-off-by: Artur Rojek <contact@artur-rojek.eu>
This commit is contained in:
Artur Rojek 2022-12-04 16:57:08 +01:00 committed by Anonymous Maarten
parent 49d8e963f4
commit 0343e53b07
1 changed files with 4 additions and 2 deletions

View File

@ -332,10 +332,12 @@ FILE* OS_fopen(const char* pathname, const char* mode) {
if (strcasecmp(pBaseName, pDirent->d_name) == 0) {
strcat(pDirName, "/");
strcat(pDirName, pDirent->d_name);
return fopen(pDirName, mode);
f = fopen(pDirName, mode);
break;
}
}
return NULL;
closedir(pDir);
return f;
}
void OS_AllocateActionReplayBuffer(char** pBuffer, unsigned* pBuffer_size) {