Skip to content

Commit 4abc01b

Browse files
Dian Shengmeta-codesync[bot]
authored andcommitted
Revert D92225087: Fix generator leak in generator that fails to startup
Differential Revision: D92225087 Original commit changeset: 7635597155d9 Original Phabricator Diff: D92225087 fbshipit-source-id: c501d919b401fd1bf4dd430f3d3c06dfe2f60b8f
1 parent 8002ab1 commit 4abc01b

1 file changed

Lines changed: 0 additions & 18 deletions

File tree

cinderx/Jit/codegen/gen_asm.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -368,19 +368,8 @@ PyObject* resumeInInterpreter(
368368
// exception state, so we don't need to do any cleanup after
369369
// _PyEval_EvalFrame. Note: We only set this up if it's not already set
370370
// (e.g., jitgen_am_send may have already set it up before we got here).
371-
//
372-
// Additionally, if the generator was never returned to the caller (i.e.,
373-
// exception occurred before RETURN_GENERATOR), we need to decref the
374-
// generator since nobody owns the reference. We detect this by checking
375-
// if gi_frame_state was FRAME_CREATED before executing.
376-
PyGenObject* gen_to_cleanup = nullptr;
377371
if (frame->owner == FRAME_OWNED_BY_GENERATOR) {
378372
PyGenObject* gen = _PyGen_GetGeneratorFromFrame(frame);
379-
if (gen->gi_frame_state == FRAME_CREATED) {
380-
// This generator was never returned to the caller (before
381-
// RETURN_GENERATOR). If an exception occurs, we need to clean it up.
382-
gen_to_cleanup = gen;
383-
}
384373
if (tstate->exc_info != &gen->gi_exc_state) {
385374
gen->gi_exc_state.previous_item = tstate->exc_info;
386375
tstate->exc_info = &gen->gi_exc_state;
@@ -389,13 +378,6 @@ PyObject* resumeInInterpreter(
389378

390379
result = _PyEval_EvalFrame(tstate, frame, err_occurred);
391380

392-
// If exception occurred before RETURN_GENERATOR, the generator was never
393-
// returned to anyone. The JIT created the generator early, but the caller
394-
// never received it. We need to decref it to avoid a memory leak.
395-
if (result == nullptr && gen_to_cleanup != nullptr) {
396-
Py_DECREF(gen_to_cleanup);
397-
}
398-
399381
frame = prev_frame;
400382

401383
err_occurred = result == nullptr;

0 commit comments

Comments
 (0)