diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2006-08-19 04:22:33 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2006-08-19 04:22:33 (GMT) |
commit | 6cbb72653919e64a1b33b11a18604d42a928dcb4 (patch) | |
tree | 0bc836da0dc0d8b09456d02367d65cfdf9b6bca8 /Objects | |
parent | 0b21b43d491220ae51eebc4df9ba6cf616265c7c (diff) | |
download | cpython-6cbb72653919e64a1b33b11a18604d42a928dcb4.zip cpython-6cbb72653919e64a1b33b11a18604d42a928dcb4.tar.gz cpython-6cbb72653919e64a1b33b11a18604d42a928dcb4.tar.bz2 |
Move initialization of interned strings to before allocating the
object so we don't leak op. (Fixes an earlier patch to this code)
Klockwork #350
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/classobject.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c index b79f06e..e739cc6 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -91,8 +91,22 @@ PyClass_New(PyObject *bases, PyObject *dict, PyObject *name) } Py_INCREF(bases); } + + if (getattrstr == NULL) { + getattrstr = PyString_InternFromString("__getattr__"); + if (getattrstr == NULL) + goto alloc_error; + setattrstr = PyString_InternFromString("__setattr__"); + if (setattrstr == NULL) + goto alloc_error; + delattrstr = PyString_InternFromString("__delattr__"); + if (delattrstr == NULL) + goto alloc_error; + } + op = PyObject_GC_New(PyClassObject, &PyClass_Type); if (op == NULL) { +alloc_error: Py_DECREF(bases); return NULL; } @@ -101,17 +115,7 @@ PyClass_New(PyObject *bases, PyObject *dict, PyObject *name) op->cl_dict = dict; Py_XINCREF(name); op->cl_name = name; - if (getattrstr == NULL) { - getattrstr = PyString_InternFromString("__getattr__"); - if (getattrstr == NULL) - return NULL; - setattrstr = PyString_InternFromString("__setattr__"); - if (setattrstr == NULL) - return NULL; - delattrstr = PyString_InternFromString("__delattr__"); - if (delattrstr == NULL) - return NULL; - } + op->cl_getattr = class_lookup(op, getattrstr, &dummy); op->cl_setattr = class_lookup(op, setattrstr, &dummy); op->cl_delattr = class_lookup(op, delattrstr, &dummy); |