summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2014-09-30 12:54:39 (GMT)
committerGeorg Brandl <georg@python.org>2014-09-30 12:54:39 (GMT)
commit21bf3f942be920f3b051f6af43f7c37b9aa5cff3 (patch)
treeb3d710b9166372fc1a83fa5f4af87c1a55a75b42
parenteaca8616ab0e219ebb5cf37d495f4bf336ec0f5e (diff)
downloadcpython-21bf3f942be920f3b051f6af43f7c37b9aa5cff3.zip
cpython-21bf3f942be920f3b051f6af43f7c37b9aa5cff3.tar.gz
cpython-21bf3f942be920f3b051f6af43f7c37b9aa5cff3.tar.bz2
Issue #22517: When a io.BufferedRWPair object is deallocated, clear its
weakrefs.
-rw-r--r--Lib/test/test_io.py6
-rw-r--r--Misc/NEWS3
-rw-r--r--Modules/_io/bufferedio.c2
3 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 8ef314e..72a844f 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -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
diff --git a/Misc/NEWS b/Misc/NEWS
index 44b0e96..c6df72b 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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.
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
index a8278d4..f788e5c 100644
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -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);