Skip to content

gh-146102: Fix various bugs in compiler pipeline from bug report#146443

Open
A0su wants to merge 2 commits intopython:mainfrom
A0su:fix_error_handling_and_ref_leaks_in_compiler
Open

gh-146102: Fix various bugs in compiler pipeline from bug report#146443
A0su wants to merge 2 commits intopython:mainfrom
A0su:fix_error_handling_and_ref_leaks_in_compiler

Conversation

@A0su
Copy link
Contributor

@A0su A0su commented Mar 26, 2026

Compiler Pipeline (codegen + compile + symtable + flowgraph + assemble) | 6 FIX

codegen.c (6,632 lines) — 4 FIX

  1. NULL deref + ref leak in codegen_setup_annotations_scope (line 716-720): PyLong_FromLong result not NULL-checked, passed to ADDOP_LOAD_CONST which dereferences it. Also never DECREF'd even on success.
  2. Ref leak of mangled in codegen_nameop (line 3280): RETURN_IF_ERROR(scope) early-returns without DECREF'ing mangled from _PyCompile_MaybeMangle.
  3. Unchecked _PyCompile_PushFBlock in codegen_unwind_fblock_stack (line 669): Return value silently discarded, error lost, frame block stack left inconsistent.

compile.c (1,772 lines) — 1 FIX

  1. Ref leak of orig in _PyCompile_TweakInlinedComprehensionScopes (line 1096-1114): PyDict_GetItemRef returns new ref in orig, never DECREF'd on any path (success or error). Leaks on every inlined comprehension.

assemble.c (802 lines) — 1 FIX

  1. assemble_emit_instr returns ERROR without exception (line 420-421): Bytecode overflow check returns ERROR without PyErr_NoMemory() → SystemError.

symtable.c (3,355 lines) — 0 FIX (clean)

flowgraph.c (4,088 lines) — 0 FIX (clean)

Did not fix

  1. Ref leak of mangled in codegen_deferred_annotations_body (line 792-818)
    • I do not see a simple way to fix this without overhauling the macros (ADDOP* & VISIT) that can early return

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant