You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
chore(profiling): increase ref before stealing (#15031)
## Description
Noticed this while looking into crashes related to the memory profiler.
[See notebook
here](https://app.datadoghq.com/notebook/13359436/memory-profiler-crashes).
We are not sure whether this would be root cause of such crashes, but
still think it's 'logically' correct to increment the reference before
calling `PyTuple_SET_ITEM()`.
When you call `PyTuple_SET_ITEM(p, pos, obj);`, then the ownership of
the object `o` is transferred to the tuple.
- https://docs.python.org/3/c-api/tuple.html#c.PyTuple_SET_ITEM
- https://docs.python.org/3/c-api/intro.html#reference-count-details
> Stealing a reference means that when you pass a reference to a
function, that function assumes that it now owns that reference, and you
are not responsible for it any longer
> When you want to keep using an object although the reference to it
will be stolen, use
[Py_INCREF()](https://docs.python.org/3/c-api/refcounting.html#c.Py_INCREF)
to grab another reference before calling the reference-stealing
function.
<!-- Provide an overview of the change and motivation for the change -->
## Testing
<!-- Describe your testing strategy or note what tests are included -->
## Risks
<!-- Note any risks associated with this change, or "None" if no risks
-->
## Additional Notes
<!-- Any other information that would be helpful for reviewers -->
0 commit comments