diff options
author | Georg Brandl <georg@python.org> | 2011-02-19 21:47:02 +0000 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2011-02-19 21:47:02 +0000 |
commit | 934616599f5f0bab03e7484e6bb1092ea265e5c5 (patch) | |
tree | a43aee56bd481024b7ed7f187329a3686cc289af /Objects | |
parent | f1184754f3a8df3c7619ec6a5507f6d2f0a0c35e (diff) | |
download | cpython-934616599f5f0bab03e7484e6bb1092ea265e5c5.tar.gz |
#11249: in PyType_FromSpec, copy tp_doc slot since it usually will point to a static string literal which should not be deallocated together with the type.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/typeobject.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index e9c7591b81..b1fe44ebe4 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -2347,6 +2347,17 @@ PyObject* PyType_FromSpec(PyType_Spec *spec) goto fail; } *(void**)(res_start + slotoffsets[slot->slot]) = slot->pfunc; + + /* need to make a copy of the docstring slot, which usually + points to a static string literal */ + if (slot->slot == Py_tp_doc) { + ssize_t len = strlen(slot->pfunc)+1; + char *tp_doc = PyObject_MALLOC(len); + if (tp_doc == NULL) + goto fail; + memcpy(tp_doc, slot->pfunc, len); + res->ht_type.tp_doc = tp_doc; + } } return (PyObject*)res; |