[CPyCppyy] Do not decref a constructor result on Windows - #21157
Merged
Conversation
guitargeek
force-pushed
the
python_dev
branch
2 times, most recently
from
February 4, 2026 13:24
eb13c60 to
88c07d3
Compare
Test Results 23 files 23 suites 3d 16h 55m 26s ⏱️ Results for commit 03753f1. ♻️ This comment has been updated with latest results. |
guitargeek
force-pushed
the
python_dev
branch
from
February 5, 2026 07:52
88c07d3 to
b622cbc
Compare
guitargeek
force-pushed
the
python_dev
branch
2 times, most recently
from
March 30, 2026 20:13
de3e2e9 to
0701b48
Compare
guitargeek
force-pushed
the
python_dev
branch
2 times, most recently
from
August 7, 2026 09:03
331f2d2 to
073158e
Compare
aaronj0
approved these changes
Aug 7, 2026
aaronj0
left a comment
Contributor
There was a problem hiding this comment.
Changes on the cppyy side LGTM!
CPPMethod::ExecuteFast() ends with a Windows-only block that turns a
result returned with a pending Python exception into a failure, to cover
the PyException throw not propagating there:
#ifdef _WIN32
if (PyErr_Occurred()) {
Py_XDECREF(result);
result = nullptr;
}
#endif
ExecuteFast() is shared by every CPPMethod subclass, including
CPPConstructor, whose executor is ConstructorExecutor. That one does not
return a PyObject* at all: it returns the address of the newly
constructed C++ object, cast to PyObject* for CPPConstructor::Call() to
unpack. Decref'ing that address treats arbitrary C++ object memory as a
PyObject and corrupts the heap.
Ask the method whether its executor hands back a real PyObject* before
dropping a reference. The object is leaked instead, which is acceptable
on the error path of a call that is about to be reported as failed.
🤖 Done with the help of AI
Contributor
Author
|
Thanks for the review! I removed all non-cppyy commits from this PR, so this part can already been merged. The part about using Once they are gone, I'll re-start the effort with the Python development module. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CPPMethod::ExecuteFast() ends with a Windows-only block that turns a
result returned with a pending Python exception into a failure, to cover
the PyException throw not propagating there:
ExecuteFast() is shared by every CPPMethod subclass, including
CPPConstructor, whose executor is ConstructorExecutor. That one does not
return a PyObject* at all: it returns the address of the newly
constructed C++ object, cast to PyObject* for CPPConstructor::Call() to
unpack. Decref'ing that address treats arbitrary C++ object memory as a
PyObject and corrupts the heap.
Ask the method whether its executor hands back a real PyObject* before
dropping a reference. The object is leaked instead, which is acceptable
on the error path of a call that is about to be reported as failed.
🤖 Done with the help of AI