8000 Issue #22517: When a io.BufferedRWPair object is deallocated, clear its · python/cpython@21bf3f9 · GitHub
[go: up one dir, main page]

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

Appearance settings

Commit 21bf3f9

Browse files
committed
Issue #22517: When a io.BufferedRWPair object is deallocated, clear its
weakrefs.
1 parent eaca861 commit 21bf3f9

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

Lib/test/test_io.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,12 @@ def isatty(self):
14541454
pair = self.tp(SelectableIsAtty(True), SelectableIsAtty(True))
14551455
self.assertTrue(pair.isatty())
14561456

1457+
def test_weakref_clearing(self):
1458+
brw = self.tp(self.MockRawIO(), self.MockRawIO())
1459+
ref = weakref.ref(brw)
1460+
brw = None
1461+
ref = None # Shouldn't segfault.
1462+
14571463
class CBufferedRWPairTest(BufferedRWPairTest):
14581464
tp = io.BufferedRWPair
14591465

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.2.6?
1010
Library
1111
-------
1212

13+
- Issue #22517: When a io.BufferedRWPair object is deallocated, clear its
14+
weakrefs.
15+
1316
- Issue #16041: CVE-2013-1752: poplib: Limit maximum line lengths to 2048 to
1417
prevent readline() calls from consuming too much memory. Patch by Jyrki
1518
Pulliainen.

Modules/_io/bufferedio.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,6 +2141,8 @@ static void
21412141
bufferedrwpair_dealloc(rwpair *self)
21422142
{
21432143
_PyObject_GC_UNTRACK(self);
2144+
if (self->weakreflist != NULL)
2145+
PyObject_ClearWeakRefs((PyObject *)self);
21442146
Py_CLEAR(self->reader);
21452147
Py_CLEAR(self->writer);
21462148
Py_CLEAR(self->dict);

0 commit comments

Comments
 (0)
0