Skip to content
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

IOS/FS: Add a scoped FD class to make it harder to leak FDs #9619

Merged
merged 1 commit into from Apr 23, 2021

Conversation

leoetlino
Copy link
Member

This changes FileSystemProxy::Open to return a file descriptor wrapper
that will ensure the FD is closed when it goes out of scope.

By using such a wrapper we make it more difficult to forget to close
file descriptors.

This fixes a leak in ReadBootContent. I should have added such a class
from the beginning... In practice, I don't think this would have caused
any obvious issue because ReadBootContent is only called after an IOS
relaunch -- which clears all FDs -- and most titles do not get close
to the FD limit.

Source/Core/Core/IOS/ES/Formats.cpp Outdated Show resolved Hide resolved
Source/Core/Core/IOS/ES/Formats.cpp Outdated Show resolved Hide resolved
Source/Core/Core/IOS/FS/FileSystemProxy.h Outdated Show resolved Hide resolved
Source/Core/Core/IOS/FS/FileSystemProxy.h Outdated Show resolved Hide resolved
@iwubcode

This comment has been minimized.

@leoetlino
Copy link
Member Author

Like you have to remember to call it to properly close the object

No, Release does the opposite: it's like unique_ptr<T>::release, it relinquishes control of the file descriptor so that the caller is now responsible for closing the file (with unique_ptr you'd need to delete the pointer yourself after calling release).

It is necessary when handles are directly exposed to the emulated console, because what is responsible for closing the handle is emulated code, not Dolphin.

@leoetlino
Copy link
Member Author

All comments addressed, I think.

This changes FileSystemProxy::Open to return a file descriptor wrapper
that will ensure the FD is closed when it goes out of scope.

By using such a wrapper we make it more difficult to forget to close
file descriptors.

This fixes a leak in ReadBootContent. I should have added such a class
from the beginning... In practice, I don't think this would have caused
any obvious issue because ReadBootContent is only called after an IOS
relaunch -- which clears all FDs -- and most titles do not get close
to the FD limit.
@JosJuice JosJuice merged commit be57756 into dolphin-emu:master Apr 23, 2021
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants