Skip to content

BUG: Fixed file handle leak in array_tofile.#17775

Merged
charris merged 6 commits intonumpy:maintenance/1.19.xfrom
charris:backport-17598
Nov 15, 2020
Merged

BUG: Fixed file handle leak in array_tofile.#17775
charris merged 6 commits intonumpy:maintenance/1.19.xfrom
charris:backport-17598

Conversation

@charris
Copy link
Copy Markdown
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.
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.

2 participants