Skip to content

gh-162246: Fix leak when re-initializing BufferedRWPair - #162405

Merged
cmaloney merged 1 commit into
python:mainfrom
cmaloney:gh-162246-rwpair-reinit-leak
Nov 22, 2026
Merged

cmaloney merged 1 commit into
python:mainfrom
cmaloney:gh-162246-rwpair-reinit-leak

Conversation

@cmaloney

@cmaloney cmaloney commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Calling BufferedRWPair.__init__() on an already initialized object overwrote the reader and writer pointers without releasing the previous objects. Build the new reader and writer first, then swap them in, releasing the old writer before the old reader as in bufferedrwpair_clear().

Make the Python implementation release the old writer before the old reader too, so pending writes are not lost when both share a raw stream.

Calling `BufferedRWPair.__init__()` on an already initialized object
overwrote the reader and writer pointers without releasing the previous
objects. Build the new reader and writer first, then swap them in,
releasing the old writer before the old reader as in
`bufferedrwpair_clear()`.

Make the Python implementation release the old writer before the old
reader too, so pending writes are not lost when both share a raw stream.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cmaloney cmaloney added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Nov 21, 2026
@cmaloney
cmaloney merged commit 5257a3d into python:main Nov 22, 2026
110 of 111 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @cmaloney for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@cmaloney
cmaloney deleted the gh-162246-rwpair-reinit-leak branch November 22, 2026 20:18
@miss-islington-app

Copy link
Copy Markdown

Sorry, @cmaloney, I could not cleanly backport this to 3.14 due to a conflict.

Please backport manually with cherry_picker, see the devguide for more information.

cherry_picker 5257a3d039c1946a09bb63b5810546ff99208a70 3.14

@bedevere-app

bedevere-app Bot commented Nov 22, 2026

Copy link
Copy Markdown

GH-162456 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 22, 2026
@bedevere-app

bedevere-app Bot commented Nov 22, 2026

Copy link
Copy Markdown

GH-162458 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 22, 2026
cmaloney added a commit that referenced this pull request Nov 22, 2026
…162405) (#162456)

gh-162246: Fix leak when re-initializing `BufferedRWPair` (GH-162405)

Calling `BufferedRWPair.__init__()` on an already initialized object
overwrote the reader and writer pointers without releasing the previous
objects. Build the new reader and writer first, then swap them in,
releasing the old writer before the old reader as in
`bufferedrwpair_clear()`.

Make the Python implementation release the old writer before the old
reader too, so pending writes are not lost when both share a raw stream.
(cherry picked from commit 5257a3d)

Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
cmaloney added a commit that referenced this pull request Nov 22, 2026
…162405) (#162458)

Calling `BufferedRWPair.__init__()` on an already initialized object
overwrote the reader and writer pointers without releasing the previous
objects. Build the new reader and writer first, then swap them in,
releasing the old writer before the old reader as in
`bufferedrwpair_clear()`.

Make the Python implementation release the old writer before the old
reader too, so pending writes are not lost when both share a raw stream.
(cherry picked from commit 5257a3d)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant