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-143249: Fix buffer leak when overlapped operation fails to start (OS-Windows)#143250

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
kumaraditya303 merged 8 commits intopython:mainfromhyongtao-code:fix-mem-leak
Jan 13, 2026

Conversation

@hyongtao-code
Copy link
Contributor

@hyongtao-codehyongtao-code commentedDec 28, 2025
edited by picnixz
Loading

On Windows, some overlapped I/O operations leak buffers when they fail to start, notably inWSASendTo(),WSARecvFrom(), andWSARecvFromInto().

This change ensures that buffers are released on failure by clearing the overlapped state, following the same pattern used in other overlapped error paths. This issue is similar in nature to commit5485085, which fixed related overlapped cleanup problems.

Python script for tracking leaks

importsysimport_overlappeddeftotal():returnsys.gettotalrefcount()ifnothasattr(sys,"gettotalrefcount"):raiseSystemExit("need a debug build (Py_DEBUG) for gettotalrefcount")before=total()N=20000STEP=1000foriinrange(1,N+1):ov=_overlapped.Overlapped()buf=memoryview(bytearray(4096))try:ov.WSASendTo(0x1234,buf,0, ("127.0.0.1",1))exceptOSError:passifi%STEP==0:now=total()print(f"{i:6d}: totalrefcount delta ={now-before:+d}")after=total()print(f"done: N={N}, totalrefcount delta ={after-before:+d}")

Result without the patch

d:\MyCode\cpython\PCbuild\amd64>python_d.exe py_overlapped_leak.py  1000: totalrefcount delta = +4007  2000: totalrefcount delta = +8009  3000: totalrefcount delta = +11906  4000: totalrefcount delta = +15906  5000: totalrefcount delta = +19906...... 19000: totalrefcount delta = +75906 20000: totalrefcount delta = +79906done: N=20000, totalrefcount delta = +79905

Result with the patch

d:\MyCode\cpython\PCbuild\amd64>python_d.exe py_overlapped_leak.py  1000: totalrefcount delta = +10  2000: totalrefcount delta = +10  3000: totalrefcount delta = +10  4000: totalrefcount delta = +10  5000: totalrefcount delta = +10...... 19000: totalrefcount delta = +10 20000: totalrefcount delta = +10done: N=20000, totalrefcount delta = +9

yihong0618 reacted with thumbs up emoji
picnixz
picnixz previously approved these changesDec 28, 2025
Copy link
Member

@picnixzpicnixz left a comment
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You'll need a NEWS entry for that and some tests as well. Please add them so that we can run them under the refleak bot as well.

cc@zooba

@picnixzpicnixz dismissed theirstale reviewDecember 28, 2025 14:41

wrong button

@picnixzpicnixz requested a review fromzoobaDecember 28, 2025 14:44
@hyongtao-code
Copy link
ContributorAuthor

and some tests as well

Thanks for the review. I will add a suitable test case.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@serhiy-storchakaserhiy-storchaka added needs backport to 3.13bugs and security fixes needs backport to 3.14bugs and security fixes labelsDec 29, 2025
Copy link
Member

@serhiy-storchakaserhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM. 👍

yihong0618 reacted with thumbs up emoji
@kumaraditya303kumaraditya303 merged commit103a384 intopython:mainJan 13, 2026
54 checks passed
@miss-islington-app
Copy link

Thanks@hyongtao-code for the PR, and@kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestJan 13, 2026
…tart on windows (pythonGH-143250)(cherry picked from commit103a384)Co-authored-by: Yongtao Huang <yongtaoh2022@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestJan 13, 2026
…tart on windows (pythonGH-143250)(cherry picked from commit103a384)Co-authored-by: Yongtao Huang <yongtaoh2022@gmail.com>
@bedevere-app
Copy link

GH-143795 is a backport of this pull request to the3.14 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.14bugs and security fixes labelJan 13, 2026
@bedevere-app
Copy link

GH-143796 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelJan 13, 2026
kumaraditya303 pushed a commit that referenced this pull requestJan 13, 2026
…start on windows (GH-143250) (#143796)gh-143249: Fix buffer leak when overlapped operation fails to start on windows (GH-143250)(cherry picked from commit103a384)Co-authored-by: Yongtao Huang <yongtaoh2022@gmail.com>
kumaraditya303 pushed a commit that referenced this pull requestJan 13, 2026
…start on windows (GH-143250) (#143795)gh-143249: Fix buffer leak when overlapped operation fails to start on windows (GH-143250)(cherry picked from commit103a384)Co-authored-by: Yongtao Huang <yongtaoh2022@gmail.com>
@hyongtao-codehyongtao-code deleted the fix-mem-leak branchJanuary 25, 2026 12:44
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@picnixzpicnixzpicnixz left review comments

@serhiy-storchakaserhiy-storchakaserhiy-storchaka approved these changes

@kumaraditya303kumaraditya303kumaraditya303 approved these changes

@zoobazoobaAwaiting requested review from zooba

@1st11st1Awaiting requested review from 1st11st1 is a code owner

@asvetlovasvetlovAwaiting requested review from asvetlovasvetlov is a code owner

@willingcwillingcAwaiting requested review from willingcwillingc is a code owner

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@hyongtao-code@serhiy-storchaka@picnixz@kumaraditya303

[8]ページ先頭

©2009-2026 Movatter.jp