summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2021-12-07 18:05:48 (GMT)
committerGitHub <noreply@github.com>2021-12-07 18:05:48 (GMT)
commit064e53d19aea6d6906fa8f7706a2556a2c293ccd (patch)
tree1045aeef70bb8be8b48072e1c56a63bdf46ccfa8 /Python
parentd596acbd3b4f6716ed98895eb0b48e9830e0b320 (diff)
downloadcpython-064e53d19aea6d6906fa8f7706a2556a2c293ccd.zip
cpython-064e53d19aea6d6906fa8f7706a2556a2c293ccd.tar.gz
cpython-064e53d19aea6d6906fa8f7706a2556a2c293ccd.tar.bz2
Fix leak when an exception is raised during generator creation. (GH-29960)
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c27
1 files changed, 7 insertions, 20 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 446772d..c22af02 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -5852,24 +5852,6 @@ fail_post_args:
return -1;
}
-static int
-initialize_coro_frame(InterpreterFrame *frame, PyThreadState *tstate,
- PyFunctionObject *func, PyObject *locals,
- PyObject *const *args, Py_ssize_t argcount,
- PyObject *kwnames)
-{
- assert(is_tstate_valid(tstate));
- assert(func->func_defaults == NULL || PyTuple_CheckExact(func->func_defaults));
- PyCodeObject *code = (PyCodeObject *)func->func_code;
- _PyFrame_InitializeSpecials(frame, func, locals, code->co_nlocalsplus);
- for (int i = 0; i < code->co_nlocalsplus; i++) {
- frame->localsplus[i] = NULL;
- }
- assert(frame->frame_obj == NULL);
- return initialize_locals(tstate, func, frame->localsplus, args, argcount, kwnames);
-}
-
-
/* Consumes all the references to the args */
static PyObject *
make_coro(PyThreadState *tstate, PyFunctionObject *func,
@@ -5883,12 +5865,17 @@ make_coro(PyThreadState *tstate, PyFunctionObject *func,
return NULL;
}
InterpreterFrame *frame = (InterpreterFrame *)((PyGenObject *)gen)->gi_iframe;
- if (initialize_coro_frame(frame, tstate, func, locals, args, argcount, kwnames)) {
+ PyCodeObject *code = (PyCodeObject *)func->func_code;
+ _PyFrame_InitializeSpecials(frame, func, locals, code->co_nlocalsplus);
+ for (int i = 0; i < code->co_nlocalsplus; i++) {
+ frame->localsplus[i] = NULL;
+ }
+ ((PyGenObject *)gen)->gi_frame_valid = 1;
+ if (initialize_locals(tstate, func, frame->localsplus, args, argcount, kwnames)) {
Py_DECREF(gen);
return NULL;
}
frame->generator = gen;
- ((PyGenObject *)gen)->gi_frame_valid = 1;
return gen;
}