Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-120754: Fix memory leak in FileIO.__init__()#124225

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
vstinner merged 1 commit intopython:mainfromvstinner:fileio_init
Sep 18, 2024

Conversation

@vstinner
Copy link
Member

@vstinnervstinner commentedSep 18, 2024
edited by bedevere-appbot
Loading

Free 'self->stat_atopen' before assigning it, since io.FileIO.init() can be called multiple times manually (especially by test_io).

Free 'self->stat_atopen' before assigning it, sinceio.FileIO.__init__() can be called multiple times manually(especially by test_io).
@vstinner
Copy link
MemberAuthor

cc@cmaloney

@cmaloney
Copy link
Contributor

👍 Definitely where the leak is happening / my own tracking finds same location.https://vstinner.github.io/debug-python-refleak.html really helpful in tracking down, thanks for writing up.

There's a number of cases whereself->fd is changed but the cached information about the file (now stat_atopen, previously estimated_size and _blksize) aren't changed. I started tracking those down (https://github.com/python/cpython/compare/main...cmaloney:cpython:cmaloney/fix_closefd_norealloc?expand=1). Happy with a much more minimal fix to get bots green. Trying to find a refactor so all the closefd logic whichfeels fairly replicated across the code at the moment can hopefully get deduped a lot while fixing potential corner case issues.

vstinner reacted with thumbs up emoji

@vstinnervstinner merged commit43cd7aa intopython:mainSep 18, 2024
@vstinnervstinner deleted the fileio_init branchSeptember 18, 2024 22:11
@vstinner
Copy link
MemberAuthor

(https://github.com/python/cpython/compare/main...cmaloney:cpython:cmaloney/fix_closefd_norealloc?expand=1)

Only allocating (PyMem_New)stat_atopen if it's NULL sounds like a better fix than my fix. I merged my fix anyway since you approved it and I would like to repair buildbot as soon as possible.

You might include your better fix in a following PR if you want, since you planned more changes for io if I understood correctly.

Thanks for reviewing my fix!

cmaloney reacted with thumbs up emoji

@cmaloney
Copy link
Contributor

cmaloney commentedSep 18, 2024
edited
Loading

Yep, will make more PRs stat_atopen got several patches moving again.

  1. isatty at open to replaceGH-120754: Remove isatty call during regular open #121593 and fixAvoid calling isatty() for most open() calls #90102
  2. "clear out cached stat result anytime self->fd is changed" (followup from this PR)
  3. Potentially clear out stat_atopen on seekUnbounded reads byzipfile may cause aMemoryError. #113977. That is a potentially more comprehensive solution to code that doesfile.seek() thenfile.read(), but also intheory the "check position in file if file is large" code should make unnecessary,https://github.com/python/cpython/blob/main/Modules/_io/fileio.c#L769-L783. Still trying to wrap my head aroundwhy the "get position" didn't seem to work for that issue)
vstinner reacted with thumbs up emoji

savannahostrowski pushed a commit to savannahostrowski/cpython that referenced this pull requestSep 22, 2024
Free 'self->stat_atopen' before assigning it, sinceio.FileIO.__init__() can be called multiple times manually(especially by test_io).
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@cmaloneycmaloneycmaloney approved these changes

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@vstinner@cmaloney

[8]ページ先頭

©2009-2025 Movatter.jp