changeset: 92665:4fa5239624b8 branch: 3.2 parent: 92663:76be07730f8d user: Georg Brandl date: Tue Sep 30 14:54:39 2014 +0200 files: Lib/test/test_io.py Misc/NEWS Modules/_io/bufferedio.c description: Issue #22517: When a io.BufferedRWPair object is deallocated, clear its weakrefs. diff -r 76be07730f8d -r 4fa5239624b8 Lib/test/test_io.py --- a/Lib/test/test_io.py Tue Sep 30 14:45:39 2014 +0200 +++ b/Lib/test/test_io.py Tue Sep 30 14:54:39 2014 +0200 @@ -1454,6 +1454,12 @@ 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 diff -r 76be07730f8d -r 4fa5239624b8 Misc/NEWS --- a/Misc/NEWS Tue Sep 30 14:45:39 2014 +0200 +++ b/Misc/NEWS Tue Sep 30 14:54:39 2014 +0200 @@ -10,6 +10,9 @@ 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. diff -r 76be07730f8d -r 4fa5239624b8 Modules/_io/bufferedio.c --- a/Modules/_io/bufferedio.c Tue Sep 30 14:45:39 2014 +0200 +++ b/Modules/_io/bufferedio.c Tue Sep 30 14:54:39 2014 +0200 @@ -2141,6 +2141,8 @@ 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);