Skip to content

Incorrect error handling in _PyCompile_CodeGen #153252

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

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions