-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Fix leaking file descriptors with zip pack files #40303
Conversation
@@ -45,7 +45,9 @@ static void *godot_open(void *data, const char *p_fname, int mode) { | |||
} | |||
|
|||
FileAccess *f = (FileAccess *)data; | |||
f->open(p_fname, FileAccess::READ); | |||
if (!f->is_open()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if a file is already open? Won't it fail opening the new file as requested?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear if it wants to open a different file. We might want to compare the file paths to make sure.
The integration of FileAccess with the uzip lib isn't super clean. It seems like uzip doesn't want to start with an open file, just enough information to do it on its own. But we give it a FileAccess::open
anyway. uzip then called the open callback godot_open
to open the file, even though we gave it to uzip already opened. godot_open
then calls FileAccess::open
again and seems to leave it dangling. 😬
We might want to consider starting uzip with FileAccess::create
and then call reopen unguarded.
I just noticed that there's also this PR which relates to the same code, probably trying to solve a similar issue: #42337. This code is a bit tricky as I don't know any current maintainer who is familiar with this code, so it's hard to assess changes. |
Superseded by #42337. Thanks for the contribution nevertheless! |
I encountered a very large number of open file descriptors for the zip pack file I was using.
It seems like there is possible recursive behavior related to the use of
FileAccess
as the implementation of thezlib_filefunc_def
function set.I'm not super familiar with the code. But it seems like
FileAccess::open
would heap allocates another FileAccess with no owner as well.Example stack
after patch:
Note: I encountered this in Godot 3.2.2 and 3.2.0. I haven't proven this in master (vulkan) since I have a hard time building it.