diff options
author | Benjamin Peterson <benjamin@python.org> | 2016-08-17 06:35:35 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2016-08-17 06:35:35 (GMT) |
commit | 1f0e7c99331750d1683287218cbab99dc26b2b83 (patch) | |
tree | c4ff8fc940cdbe4ceedab36b380c5556d179218b /Modules/operator.c | |
parent | 3a27b0857ef6d35911509eef88e567663bb0a0b6 (diff) | |
download | cpython-1f0e7c99331750d1683287218cbab99dc26b2b83.zip cpython-1f0e7c99331750d1683287218cbab99dc26b2b83.tar.gz cpython-1f0e7c99331750d1683287218cbab99dc26b2b83.tar.bz2 |
rearrange methodcaller_new so that the main error case does not cause uninitialized memory usage (closes #27783)
Diffstat (limited to 'Modules/operator.c')
-rw-r--r-- | Modules/operator.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/Modules/operator.c b/Modules/operator.c index 5156b6b..d6443bf 100644 --- a/Modules/operator.c +++ b/Modules/operator.c @@ -776,7 +776,7 @@ static PyObject * methodcaller_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { methodcallerobject *mc; - PyObject *name, *newargs; + PyObject *name; if (PyTuple_GET_SIZE(args) < 1) { PyErr_SetString(PyExc_TypeError, "methodcaller needs at least " @@ -789,13 +789,6 @@ methodcaller_new(PyTypeObject *type, PyObject *args, PyObject *kwds) if (mc == NULL) return NULL; - newargs = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args)); - if (newargs == NULL) { - Py_DECREF(mc); - return NULL; - } - mc->args = newargs; - name = PyTuple_GET_ITEM(args, 0); Py_INCREF(name); mc->name = name; @@ -803,6 +796,12 @@ methodcaller_new(PyTypeObject *type, PyObject *args, PyObject *kwds) Py_XINCREF(kwds); mc->kwds = kwds; + mc->args = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args)); + if (mc->args == NULL) { + Py_DECREF(mc); + return NULL; + } + PyObject_GC_Track(mc); return (PyObject *)mc; } |