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

weakrefs.
This commit is contained in:
Georg Brandl 2014-09-30 14:54:39 +02:00
parent eaca8616ab
commit 21bf3f942b
3 changed files with 11 additions and 0 deletions

View File

@ -1454,6 +1454,12 @@ class BufferedRWPairTest(unittest.TestCase):
pair = self.tp(SelectableIsAtty(True), SelectableIsAtty(True))
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):
tp = io.BufferedRWPair

View File

@ -10,6 +10,9 @@ What's New in Python 3.2.6?
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
prevent readline() calls from consuming too much memory. Patch by Jyrki
Pulliainen.

View File

@ -2141,6 +2141,8 @@ static void
bufferedrwpair_dealloc(rwpair *self)
{
_PyObject_GC_UNTRACK(self);
if (self->weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *)self);
Py_CLEAR(self->reader);
Py_CLEAR(self->writer);
Py_CLEAR(self->dict);