Skip to content

Incorrect error handling in _PyCompile_CodeGen #153252

Closed

Description

@sobolevn

Bug report

Code:

cpython/Python/compile.c

Lines 1683 to 1697 in 12ed8b1

compiler *c = new_compiler(mod, filename, pflags, optimize, arena, NULL);
if (c == NULL) {
_PyArena_Free(arena);
return NULL;
}
c->c_save_nested_seqs = true;
metadata = PyDict_New();
if (metadata == NULL) {
return NULL;
}
if (compiler_codegen(c, mod) < 0) {
goto finally;
}

The problematic part is:

cpython/Python/compile.c

Lines 1690 to 1693 in 12ed8b1

metadata = PyDict_New();
if (metadata == NULL) {
return NULL;
}

It just returns NULL: does not free the compiler on error, does not free the arena, etc. It should be goto finally.

I have a PR ready.

Linked PRs

Activity

  1. self-assigned this
    on Jul 7, 2026
  2. added
    type-bug
    interpreter-core
    on Jul 7, 2026
  3. added 4 commits that reference this issue on Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

interpreter-coretype-bug

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions