[Python-checkins] r74155 - in python/branches/py3k: Lib/test/test_memoryio.py Modules/_io/bytesio.c Modules/_io/stringio.c
alexandre.vassalotti
python-checkins at python.org
Wed Jul 22 04:24:50 CEST 2009
Author: alexandre.vassalotti
Date: Wed Jul 22 04:24:49 2009
New Revision: 74155
Log:
Issue #6242: Fix deallocator of io.StringIO and io.BytesIO.
Modified:
python/branches/py3k/Lib/test/test_memoryio.py
python/branches/py3k/Modules/_io/bytesio.c
python/branches/py3k/Modules/_io/stringio.c
Modified: python/branches/py3k/Lib/test/test_memoryio.py
==============================================================================
--- python/branches/py3k/Lib/test/test_memoryio.py (original)
+++ python/branches/py3k/Lib/test/test_memoryio.py Wed Jul 22 04:24:49 2009
@@ -338,6 +338,13 @@
self.assertEqual(test1(), buf)
self.assertEqual(test2(), buf)
+ def test_instance_dict_leak(self):
+ # Test case for issue #6242.
+ # This will be caught by regrtest.py -R if this leak.
+ for _ in range(100):
+ memio = self.ioclass()
+ memio.foo = 1
+
class PyBytesIOTest(MemoryTestMixin, MemorySeekTestMixin, unittest.TestCase):
Modified: python/branches/py3k/Modules/_io/bytesio.c
==============================================================================
--- python/branches/py3k/Modules/_io/bytesio.c (original)
+++ python/branches/py3k/Modules/_io/bytesio.c Wed Jul 22 04:24:49 2009
@@ -609,11 +609,14 @@
static void
bytesio_dealloc(bytesio *self)
{
+ _PyObject_GC_UNTRACK(self);
if (self->buf != NULL) {
PyMem_Free(self->buf);
self->buf = NULL;
}
- Py_TYPE(self)->tp_clear((PyObject *)self);
+ Py_CLEAR(self->dict);
+ if (self->weakreflist != NULL)
+ PyObject_ClearWeakRefs((PyObject *) self);
Py_TYPE(self)->tp_free(self);
}
@@ -667,7 +670,6 @@
bytesio_traverse(bytesio *self, visitproc visit, void *arg)
{
Py_VISIT(self->dict);
- Py_VISIT(self->weakreflist);
return 0;
}
@@ -675,8 +677,6 @@
bytesio_clear(bytesio *self)
{
Py_CLEAR(self->dict);
- if (self->weakreflist != NULL)
- PyObject_ClearWeakRefs((PyObject *)self);
return 0;
}
Modified: python/branches/py3k/Modules/_io/stringio.c
==============================================================================
--- python/branches/py3k/Modules/_io/stringio.c (original)
+++ python/branches/py3k/Modules/_io/stringio.c Wed Jul 22 04:24:49 2009
@@ -509,11 +509,15 @@
stringio_dealloc(stringio *self)
{
_PyObject_GC_UNTRACK(self);
+ self->ok = 0;
+ if (self->buf) {
+ PyMem_Free(self->buf);
+ self->buf = NULL;
+ }
Py_CLEAR(self->readnl);
Py_CLEAR(self->writenl);
Py_CLEAR(self->decoder);
- if (self->buf)
- PyMem_Free(self->buf);
+ Py_CLEAR(self->dict);
if (self->weakreflist != NULL)
PyObject_ClearWeakRefs((PyObject *) self);
Py_TYPE(self)->tp_free(self);
More information about the Python-checkins
mailing list