Skip to content

pylifecycle.c: Multiple init/fini cleanup bugs #149630

@Wulian233

Description

@Wulian233

Bug report

Bug description:

Parent: #146102

https://gist.github.com/devdanzin/b022ff2d1304a4b2b8d3d8750abd8da5

pylifecycle.c: Multiple init/fini cleanup bugs

Summary

5 bugs in interpreter lifecycle:

  1. new_interpreter (line 2534): return status bypasses switch-back after save_tstate detach → thread state corruption.
  2. pycore_init_builtins (line 860): Direct return leaks bimod ref.
  3. add_main_module (line 2762): bimod/loader refs leaked on PyDict_SetItemString failure.
  4. finalize_clear_modules_dict (line 1685): Return value of PyObject_CallMethodNoArgs never DECREF'd.
  5. init_sys_streams (line 3019-3031): Unchecked PySys_SetObject for stdin/stdout (stderr correctly checked).

CPython versions tested on:

CPython main branch, 3.15

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions