[Python-checkins] bpo-46347: Fix PyEval_EvalCodeEx to correctly cleanup in error paths (#30553)
1st1
webhook-mailer at python.org
Tue Jan 11 19:17:51 EST 2022
https://github.com/python/cpython/commit/6f9ca53a6ac343a5663cc5c52546acf9a63b605a
commit: 6f9ca53a6ac343a5663cc5c52546acf9a63b605a
branch: 3.10
author: Yury Selivanov <yury at edgedb.com>
committer: 1st1 <yury at edgedb.com>
date: 2022-01-11T16:17:42-08:00
summary:
bpo-46347: Fix PyEval_EvalCodeEx to correctly cleanup in error paths (#30553)
files:
M Python/ceval.c
diff --git a/Python/ceval.c b/Python/ceval.c
index e906076e27e56..ab10b4166d6d2 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -5090,7 +5090,7 @@ PyEval_EvalCodeEx(PyObject *_co, PyObject *globals, PyObject *locals,
PyObject *kwdefs, PyObject *closure)
{
PyThreadState *tstate = _PyThreadState_GET();
- PyObject *res;
+ PyObject *res = NULL;
PyObject *defaults = _PyTuple_FromArray(defs, defcount);
if (defaults == NULL) {
return NULL;
@@ -5103,23 +5103,19 @@ PyEval_EvalCodeEx(PyObject *_co, PyObject *globals, PyObject *locals,
if (locals == NULL) {
locals = globals;
}
- PyObject *kwnames;
+ PyObject *kwnames = NULL;
PyObject *const *allargs;
- PyObject **newargs;
+ PyObject **newargs = NULL;
if (kwcount == 0) {
allargs = args;
- kwnames = NULL;
}
else {
kwnames = PyTuple_New(kwcount);
if (kwnames == NULL) {
- res = NULL;
goto fail;
}
newargs = PyMem_Malloc(sizeof(PyObject *)*(kwcount+argcount));
if (newargs == NULL) {
- res = NULL;
- Py_DECREF(kwnames);
goto fail;
}
for (int i = 0; i < argcount; i++) {
@@ -5149,11 +5145,9 @@ PyEval_EvalCodeEx(PyObject *_co, PyObject *globals, PyObject *locals,
res = _PyEval_Vector(tstate, &constr, locals,
allargs, argcount,
kwnames);
- if (kwcount) {
- Py_DECREF(kwnames);
- PyMem_Free(newargs);
- }
fail:
+ Py_XDECREF(kwnames);
+ PyMem_Free(newargs);
Py_DECREF(defaults);
return res;
}
More information about the Python-checkins
mailing list