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

BUG: Fixed file handle leak in array_tofile. #17775

Merged
merged 6 commits into from Nov 15, 2020

Conversation

charris
Copy link
Member

@charris charris commented Nov 14, 2020

Backport of #17598.

Closes #17589

If the PyArray_ToFile call inside array_tofile fails for any reason, we leak a dup-ed file handle. This causes problems especially on Windows OS, where any subsequent attempt to delete the file will fail because NumPy is still holding an open handle.

This update ensures that we always close the handle.

The added test case forces PyArray_ToFile to fail, which triggers the original problem.

simon-graham and others added 6 commits November 14, 2020 16:35
The dup-ed file handle created in array_tofile is now closed when PyArray_ToFile fails.
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
If we pass a str to tofile() rather than an open file object, it will open a Python handle. Make sure that it gets closed correctly.
@charris charris added this to the 1.19.5 release milestone Nov 14, 2020
@charris charris merged commit 760449c into numpy:maintenance/1.19.x Nov 15, 2020
@charris charris deleted the backport-17598 branch November 15, 2020 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants