python / python/cpython

pylifecycle.c: Multiple init/fini cleanup bugs

Open
#149,630 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

interpreter-core type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

Parent: https://github.com/python/cpython/issues/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
  • gh-149631

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the parent issue and linked gist, then inspect pylifecycle.c at new_interpreter, pycore_init_builtins, add_main_module, finalize_clear_modules_dict, and init_sys_streams. Check each reported failure path and use the linked PR gh-149631 for existing context. Done means all five lifecycle cleanup issues are addressed without introducing new reference or thread-state problems.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.