summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_descr.py10
-rw-r--r--Misc/NEWS2
-rw-r--r--Objects/typeobject.c6
3 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 554e1c8a65..cef7d476e1 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -2959,6 +2959,16 @@ order (MRO) for bases """
continue
cant(cls(), cls2)
+ # Issue5283: when __class__ changes in __del__, the wrong
+ # type gets DECREF'd.
+ class O(object):
+ pass
+ class A(object):
+ def __del__(self):
+ self.__class__ = O
+ l = [A() for x in range(100)]
+ del l
+
def test_set_dict(self):
# Testing __dict__ assignment...
class C(object): pass
diff --git a/Misc/NEWS b/Misc/NEWS
index 546c7c1e13..5c074e13ca 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,6 +15,8 @@ Core and Builtins
- Issue #5787: object.__getattribute__(some_type, "__bases__") segfaulted on
some builtin types.
+- Issue #5283: Setting __class__ in __del__ caused a segfault.
+
- Issue #5759: float() didn't call __float__ on str subclasses.
Library
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index ddfc730565..7e48172fec 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -928,6 +928,9 @@ subtype_dealloc(PyObject *self)
assert(base);
}
+ /* Extract the type again; tp_del may have changed it */
+ type = Py_TYPE(self);
+
/* Call the base tp_dealloc() */
assert(basedealloc);
basedealloc(self);
@@ -1009,6 +1012,9 @@ subtype_dealloc(PyObject *self)
}
}
+ /* Extract the type again; tp_del may have changed it */
+ type = Py_TYPE(self);
+
/* Call the base tp_dealloc(); first retrack self if
* basedealloc knows about gc.
*/