bpo-38152: Fix refleak in the finalizer of AST type#16127
bpo-38152: Fix refleak in the finalizer of AST type#16127DinoV merged 1 commit intopython:masterfrom
Conversation
f9c9bf2 to
7d84e19
Compare
|
Previously this was failing, and it's passing now: I also ran all the modules that were referred to by the issue and all of them are passing now: |
|
cc @matrixise |
ammaraskar
left a comment
There was a problem hiding this comment.
LGTM with requested change.
I think a little bit of documentation change would be helpful here as well. With heap-allocated types like this, if there is a custom tp_dealloc then the user must remember to DECREF the type object.
I noticed when you introduced INCREF for heap types, you added a whatsnew entry. I think it would be advisable to add this information to https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_dealloc as well, just so there's somewhere to point to about this behavior.
I would even suggest add a comment here explaining the reason for the DECREF on the type.
| @@ -638,9 +638,13 @@ def visitModule(self, mod): | |||
| ast_dealloc(AST_object *self) | |||
There was a problem hiding this comment.
While you're in here, could you fix the typo introduced here:
Lines 1236 to 1237 in d057b89
(Py_tp_free is duplicated, once incorrectly set to PyType_GenericNew)
|
@DinoV: Please replace |
|
@ammaraskar makes sense. I'll send a PR updating the docs |
…H-16248) As mentioned in the bpo ticket, this mistake came up on two reviews: - #16127 (review) - #16071 (review) Would be nice to have it documented in a more permanent place than 3.8's whatsnew entry. https://bugs.python.org/issue38206 Automerge-Triggered-By: @encukou
…ythonGH-16248) As mentioned in the bpo ticket, this mistake came up on two reviews: - python#16127 (review) - python#16071 (review) Would be nice to have it documented in a more permanent place than 3.8's whatsnew entry. https://bugs.python.org/issue38206 Automerge-Triggered-By: @encukou
The
AST_objectwas leaking its reference to theASTtype. This change properly decreases the reference to the type at deallocation time. Also, this modifiestp_freeto usePyType_GetSlotto makePyTypeObjectopaque.https://bugs.python.org/issue38152