diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2013-04-13 15:19:05 +0100 |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2013-04-13 15:19:05 +0100 |
commit | ec7001157c7b76e89f99b124e58335adca17132a (patch) | |
tree | b740ac6686d3ee571e48e82baf7af90716c89c50 /Objects | |
parent | 020f3f9501f16d39ad95ea9213db51d7886568cf (diff) | |
download | cpython-ec7001157c7b76e89f99b124e58335adca17132a.tar.gz |
Issue #16447: Fix potential segfault when setting __name__ on a class.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/typeobject.c | 6 |
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; } |