Fix file handle leak in ZipArchive and FileAccessZip #103219
Open
+2
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, zfile was stored in a global variable inside the ZipArchive singleton, leading to a potential file handle leak when handling ZIP archives.
Since zfile is not needed at runtime, there is no reason to store it. This change ensures that the file handle is properly closed after processing, preventing unnecessary open file accumulation.
Use case:
I'm developing a game that supports user content with generic file formats (GLB, PNG, and more). We have an Asset Optimization Pipeline that converts these assets into Godot ZIP Packages. When loading thousands of these ZIPs (with ProjectSettings.load_resource_pack), we encountered issues with too many open file handles due to this bug.
This fix ensures that file handles are properly closed, improving resource management and stability when dealing with a large number of ZIP archives.