Skip to content

Commit 0343e53

Browse files
zearmadebr
authored andcommittedDec 4, 2022
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>
1 parent 49d8e96 commit 0343e53

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed
 

‎src/harness/os/linux.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,12 @@ FILE* OS_fopen(const char* pathname, const char* mode) {
332332
if (strcasecmp(pBaseName, pDirent->d_name) == 0) {
333333
strcat(pDirName, "/");
334334
strcat(pDirName, pDirent->d_name);
335-
return fopen(pDirName, mode);
335+
f = fopen(pDirName, mode);
336+
break;
336337
}
337338
}
338-
return NULL;
339+
closedir(pDir);
340+
return f;
339341
}
340342

341343
void OS_AllocateActionReplayBuffer(char** pBuffer, unsigned* pBuffer_size) {

0 commit comments

Comments
 (0)
Please sign in to comment.