gh-153210: Do not DECREF ArrayType in array_modexc when errors occur#153239
Closed
stestagg wants to merge 3 commits into
Closed
gh-153210: Do not DECREF ArrayType in array_modexc when errors occur#153239stestagg wants to merge 3 commits into
stestagg wants to merge 3 commits into
Conversation
… initialized on the array mod state, so GC / module cleanup will do this. (Ownership belongs to the state struct)
Contributor
Author
|
@sobolevn made a PR at the same time, but theirs is more comprehensive! |
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.
ArrayTypeis initialized directly on thearraymodule state struct.This means that the reference ownership of
ArrayTypebelongs to the state, NOT the local function.In two error cases,
ArrayTypewas being DECREF'd by the function. Both of these DECREFS unbalanced the refcount because the ArrayType pointer is left populated on the module state. When the module is eventually cleaned up (probably by GC), thenArrayTypeis DECREF'd again.This change just removes the DECREF's and relies on the module tp_clear to walk the deps and clean up the state for us.
Note, the test only catches this issue in a debug build. I don't know enough to know if there's a better way to write this test, but because
ArrayTypeis aType, reasoning about specific refcount numbers is hard, this approach should be robust.arraymodule import result in double-DECREF #153210