[Python-checkins] cpython (3.2): Issue #22517: When a io.BufferedRWPair object is deallocated, clear its
georg.brandl
python-checkins at python.org
Tue Sep 30 15:00:17 CEST 2014
https://hg.python.org/cpython/rev/4fa5239624b8
changeset: 92665:4fa5239624b8
branch: 3.2
parent: 92663:76be07730f8d
user: Georg Brandl <georg at python.org>
date: Tue Sep 30 14:54:39 2014 +0200
summary:
Issue #22517: When a io.BufferedRWPair object is deallocated, clear its
weakrefs.
files:
Lib/test/test_io.py | 6 ++++++
Misc/NEWS | 3 +++
Modules/_io/bufferedio.c | 2 ++
3 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -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 --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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 --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -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);
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list