Commit 629eb689 authored by Georg Brandl's avatar Georg Brandl

Issue #22517: When a io.BufferedRWPair object is deallocated, clear its

weakrefs.
parent 2431198b
...@@ -1454,6 +1454,12 @@ class BufferedRWPairTest(unittest.TestCase): ...@@ -1454,6 +1454,12 @@ class BufferedRWPairTest(unittest.TestCase):
pair = self.tp(SelectableIsAtty(True), SelectableIsAtty(True)) pair = self.tp(SelectableIsAtty(True), SelectableIsAtty(True))
self.assertTrue(pair.isatty()) self.assertTrue(pair.isatty())
def test_weakref_clearing(self):
brw = self.tp(self.MockRawIO(), self.MockRawIO())
ref = weakref.ref(brw)
brw = None
ref = None # Shouldn't segfault.
class CBufferedRWPairTest(BufferedRWPairTest): class CBufferedRWPairTest(BufferedRWPairTest):
tp = io.BufferedRWPair tp = io.BufferedRWPair
......
...@@ -10,6 +10,9 @@ What's New in Python 3.2.6? ...@@ -10,6 +10,9 @@ What's New in Python 3.2.6?
Library Library
------- -------
- Issue #22517: When a io.BufferedRWPair object is deallocated, clear its
weakrefs.
- Issue #16041: CVE-2013-1752: poplib: Limit maximum line lengths to 2048 to - Issue #16041: CVE-2013-1752: poplib: Limit maximum line lengths to 2048 to
prevent readline() calls from consuming too much memory. Patch by Jyrki prevent readline() calls from consuming too much memory. Patch by Jyrki
Pulliainen. Pulliainen.
......
...@@ -2141,6 +2141,8 @@ static void ...@@ -2141,6 +2141,8 @@ static void
bufferedrwpair_dealloc(rwpair *self) bufferedrwpair_dealloc(rwpair *self)
{ {
_PyObject_GC_UNTRACK(self); _PyObject_GC_UNTRACK(self);
if (self->weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *)self);
Py_CLEAR(self->reader); Py_CLEAR(self->reader);
Py_CLEAR(self->writer); Py_CLEAR(self->writer);
Py_CLEAR(self->dict); Py_CLEAR(self->dict);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment