summaryrefslogtreecommitdiff
path: root/Objects
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2013-04-13 15:19:05 +0100
committerMark Dickinson <dickinsm@gmail.com>2013-04-13 15:19:05 +0100
commitec7001157c7b76e89f99b124e58335adca17132a (patch)
treeb740ac6686d3ee571e48e82baf7af90716c89c50 /Objects
parent020f3f9501f16d39ad95ea9213db51d7886568cf (diff)
downloadcpython-ec7001157c7b76e89f99b124e58335adca17132a.tar.gz
Issue #16447: Fix potential segfault when setting __name__ on a class.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 6c88f53af4..be04c9e914 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -225,6 +225,7 @@ static int
type_set_name(PyTypeObject *type, PyObject *value, void *context)
{
PyHeapTypeObject* et;
+ PyObject *tmp;
if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
PyErr_Format(PyExc_TypeError,
@@ -253,10 +254,13 @@ type_set_name(PyTypeObject *type, PyObject *value, void *context)
Py_INCREF(value);
- Py_DECREF(et->ht_name);
+ /* Wait until et is a sane state before Py_DECREF'ing the old et->ht_name
+ value. (Bug #16447.) */
+ tmp = et->ht_name;
et->ht_name = value;
type->tp_name = PyString_AS_STRING(value);
+ Py_DECREF(tmp);
return 0;
}