Skip to content

fix reference count leak in PyFrame::new#6094

Merged
bschoenmaeckers merged 1 commit into
PyO3:mainfrom
davidhewitt:frame-leak
Jun 2, 2026
Merged

fix reference count leak in PyFrame::new#6094
bschoenmaeckers merged 1 commit into
PyO3:mainfrom
davidhewitt:frame-leak

Conversation

@davidhewitt

Copy link
Copy Markdown
Member

Codex security scanning spotted this; we haven't released it yet.

As far as I can tell from checking the implementation and docs of PyFrame_New, indeed the reference is not stolen so .into_ptr() was a leak.

@davidhewitt davidhewitt added the CI-skip-changelog Skip checking changelog entry label Jun 2, 2026

@bschoenmaeckers bschoenmaeckers left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tnx!

@bschoenmaeckers bschoenmaeckers enabled auto-merge June 2, 2026 10:01
@bschoenmaeckers

Copy link
Copy Markdown
Member

Will this drop the code object before the frame is dropped? Is that a problem?

@bschoenmaeckers bschoenmaeckers disabled auto-merge June 2, 2026 10:03
@davidhewitt

Copy link
Copy Markdown
Member Author

No, the Bound will be dropped at scope exit, so will clean up on any success or failure.

@bschoenmaeckers bschoenmaeckers enabled auto-merge June 2, 2026 10:04
@bschoenmaeckers bschoenmaeckers added this pull request to the merge queue Jun 2, 2026
Merged via the queue into PyO3:main with commit 62841bf Jun 2, 2026
49 checks passed
ngoldbaum pushed a commit to ngoldbaum/pyo3 that referenced this pull request Jun 2, 2026
pull Bot pushed a commit to Mu-L/pyo3 that referenced this pull request Jun 2, 2026
* Use PyModExport and PyABIInfo APIs in pymodule implementation

* Add PyModExport function

* DNM: temporarily disable append_to_inittab doctest

* fix issues seen on older pythons in CI

* fix incorrect ModuleDef setup on 3.15

* Expose both the PyInit and PyModExport initialization hooks

* fix clippy

* add changelog entry

* try use only slots for both init hooks on 3.15

* Always pass m_name and m_doc, following cpython-gh-144340

* WIP: opaque pyobject support (without Py_GIL_DISABLED)

* delete debug prints

* WIP: fix segfault

* disable append_to_inittab tests

* fix clippy

* fix ruff

* implement David's suggestion for pyobject_subclassable_native_type

* replace skipped test with real test

* fix check-feature-powerset

* fix clippy-all

* skip test that depend on struct layout on opaque pyobject builds

* Expose PyModuleDef as an opaque pointer on opaque PyObject builds

* add comments about location of opaque pointers in CPython headers

* fix test_inherited_size

* Fix doctest on _Py_OPAQUE_PYOBJECT builds

* fix build error on non-opaque builds

* mark BaseWithoutData as subclassable

* relax assert for Windows

* Make PyAny a PyVarObject only on the opaque PyObject build

* fix merge conflict resolution error

* fix buggy assertion

* Expose critical section in the limited API starting in Python 3.15

* expose critical section API in limited API

* disable warning in pyo3-ffi build script on sufficiently new Pythons

* fixup features

* Add missing error handling for `PyModule_FromSlotsAndSpec`

* passes cargo tests with the abi3t feature enabled

* passes unit tests on GIL-enabled build with abi3t feature

* fix merge mistake

* rustfmt

* fix FIXME

* replace extern "C" with extern_libpython!

* fix test

* fix merge error

* Allow abi3t builds without critical section bindings

* add FIXME

* remove default feature

* fix syntax error in noxfile

* fix issues spotted by clippy

* bring over refactoring from PyO3 PR

* working!

* Fix memory leak of iterator

* fix size hints

* delete debug statement

* Use Py_TARGET_ABI3T

* run formatter

* fix check-feature-powerset

* increment SUPPORTED_VERSIONS_CPYTHON.max

* fix conditional compilation for critical section API

* fix ruff

* fix incorrect conditional compilation guargs

* fix noxfile and ban abi3t builds on 3.14 and older

* ruff format

* attempt to fix semver-checks

* fix test-version-limits

* fix issues spotted by claude

* strip 't' for version parsing

* Adjust comments and error messages

* fix compiler warning

* more noxfile fixes

* fix ruff

* use a 3.15 interpreter to run the feature-powerset tests

* fix a few more issues caught by claude

* add comment

* use correct windows library name for abi3t

* try to fix linking

* add CPythonABI enum for pyo3-build-config InterpreterConfig

* add release note

* store ABI details in a new PythonAbi struct

* fix nox config file

* fix ffi-check

* Refactor to use the builder pattern for InterpreterConfig

* revert noxfile change

* fix clippy-all

* fix build-config test

* Fix issues linking against onld stable ABI versions

* remove load-bearing debug impls

* fix issue with InterpreterConfig::from_interpreter never returning an abi3 config

* fix clippy lint

* fix PythonAbiBuilder::from_build_env

* Only target abi3 for non-free-threaded builds

* fix logic error in InterpreterConfig::from_reader

* smooth over merge

* tests pass

* Add stub abi3t implementation

* Improve test coverage

* fix clippy

* fix 3.14t abi3 builds being a no-op

* fix ffi-check to account for private _tp_iteritem PyTypeObject slot

* expose the critical section API

* Add initial support for Python 3.15.0b1

* fix ffi docstring example

* typo fix

* fix ffi-check macro

* fix ffi examples

* make PySlot_FUNC a Rust macro

* fix clippy

* keep macros version-independent

* format extern_libpython blocks

* use an explicit type in the PySlot_FUNC macro

* fix issues seen in CI builds on older Pythons

* fix one more spot in the ffi tests

* fix type error in string-sum implementation

* add changelog entries

* remove unnecessary PartialEq implementation

* use std::slice::from_raw_parts instead of libc::memcmp

* re-add incorrectly deleted end slot

* Use PartialEq on Python 3.14 and older

* fix compiler error due to missing Debug impl

* Finish updating slots_generated and adjust types for slot IDs

* add missing cfg gate

* remove unused import

* make InterpreterConfigBuilder.extra_build_script_lines a Vec

* Add an abi3 version sanitization function, adjust error handling

* Adjust comment fragment, add TODO

* apply focused comments from self-review

* simplify modeling of free-threaded builds and Py_GIL_DISABLED build flag

* fix clippy

* relax accepting Py_GIL_DISABLED in build_flags if no target ABI is set

* more fixes and suggestions from claude

* fix fallback to version-specific builds for free-threaded abi3 builds

* More minor fixes

* expand test coverage

* more fixes

* update changelog entries

* Add missing exports to public pyo3-build-config API

* fix linux test

* minor touch-ups

* minor touch-ups

* skip redundant test

* whitespace

* more tweaks

* grammar in comment

* fix cfg gating

* activate abi3t builds

* fix PyMutex gating

* simplify windows stable ABI lib name text manipulation

* fix ruff

* fix cfg gating for critical section API

* adjust PyMutex cfg gating

* attempt to fix abi3 feature for free-threaded targets from a config file

* introduce a builder for InterpreterConfig

Co-authored-by: David Hewitt <mail@davidhewitt.dev>

* newsfragments

* fixup ubuntu test

* fixup

* fix missing `mut`

* fix merge error

* fix incorrect merge conflict resolution

* refactor is_abi3(t) in get_abit3(t)_version.is_some()

* apply suggestions from icxolu

* Make PythonAbi fields private, replace with accessor methods

* fix test-version-limits

* Apply suggestions from code review

Co-authored-by: Thomas Tanon <thomas@pellissier-tanon.fr>

* review feedback

* fix merge conflicts

* fix clippy

* re-enable functionality that depends on critical sections

* revert more unnecessary changes

* reduce diff further

* fix cfg gating for critical section guards

* Merging with David's default_lib_name_for_config_file branch

* remove unnecessary get_abi3_version().is_some()

* bring back Option

* fix comparison for ABI3T_FORWARD_COMPATIBILITY

* Apply minor suggestions from code review

* delete docs for non-pub field

* Don't define a Py_TARGET_ABI3T cfg check

* fix merge errors

* implement Icxolu's suggestion to get rid of is_abi3 and is_abi3t

* fix clippy-all

* delete unnecessary get_abit3_version() check

* Allow simultaneously enabling abi3 and abi3t features

* add release notes

* fix ruff

* really fix ruff

* don't run abi3-py38 tests on pypy

* add docs

* disable windows gil-enabled abi3t builds to work around upstream bug

* fix guide formatting

* fix internal links in guide

* fix typo in noxfile

* fix release notes

* revert now-unnecessary CI configuration change

* fix abi3t-py315 feature not re-exporting pyo3-ffi feature

* fix typos in comments

* make get_host_interpreter accept explicit abi3_version and abi3t_version arguments

* never use an abi3 version on the free-threaded build

* make build-config tests pass on 3.14t

* version-gate build-config test

* fix logic error in get_host_interpreter

* skip build-config tests for stable ABI lowering on 3.14t, which doesn't support any stable ABI

* further gate test

* attempt to fix cross-compilation issue in maturin

* only use abi3 version for non-free-threaded cross-compile

* fix incorrect version gate

* further gate test onolder python versions

* expand test-version-limits tests to cover pyo3-ffi build script logic

* Apply David's review comments

* expand cross-compilation tests

* fix ruff

* don't lower to abi3 on pypy or graalpy

* fix cross-compiling from PyPy

* skip stable abi lowering test on graalpy and pypy

* fix logic error

* simplify skipping logic

* Fix Py_UNICODE_TODECIMAL definition for PyPy

* rename USE_ABI3T_FORWARD_COMPATIBILITY to USE_STABLE_ABI_FORWARD_COMPATIBILITY

* format

* Always target abi3 on rustpython

* fix clippy

* Apply suggestions from code review

Co-authored-by: David Hewitt <mail@davidhewitt.dev>

* internal: use `hashbrown` internally if it's enabled (PyO3#6055)

* use `hashbrown` internally if it's enabled

* empty commit to trigger CI

* empty commit to trigger CI

* ci: install debug interpreter with uv (PyO3#5447)

* ci: install debug interpreter with uv

* try use rpath to link to exact interpreter

* don't emit rpath on wasm targets

* fixup clippy

* update now ui-test has landed

* fix clippy

* Update pyo3-build-config/src/lib.rs

Co-authored-by: Thomas Tanon <thomas@pellissier-tanon.fr>

* newsfragment

---------

Co-authored-by: Thomas Tanon <thomas@pellissier-tanon.fr>

* fix reference count leak in `PyFrame::new` (PyO3#6094)

* regenerate PYO3_PRINT_CONFIG example output

* delete documentation line that links to PRs

* fix build error from github suggestion

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
Co-authored-by: Thomas Tanon <thomas@pellissier-tanon.fr>
Co-authored-by: person93 <person93.person93@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI-skip-changelog Skip checking changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants