Skip to content

BUG: Fix reference count leak in str(scalar). #24211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2023
Merged

Conversation

hawkinsp
Copy link
Contributor

@hawkinsp hawkinsp commented Jul 18, 2023

PyArray_DescrFromTypeObject() returns a fresh reference to the descriptor object, which must be freed.

This leak was introduced in
670842b

The leak was released in NumPy 1.25, so this change may be a 1.25 backport candidate.

Bug found while running the Google Protobuf test suite under NumPy 1.25, which stringifies NumPy arrays in some of its tests, and has a test harness for detecting reference count leaks: https://github.com/protocolbuffers/protobuf/blob/49d3bca39f96f7709d48aaea4f5d30c11a943690/python/google/protobuf/internal/testing_refleaks.py

PyArray_DescrFromTypeObject() returns a fresh reference to the descriptor object, which must be freed.

This leak was introduced in
numpy@670842b
@ngoldbaum
Copy link
Member

Thanks @hawkinsp! I think this is clearly correct so I’m going to merge it. Heads up @mattip.

I was just talking with @seberg earlier today about updating pytest-leaks to make it easier for projects to catch this sort of thing in CI.

@ngoldbaum ngoldbaum merged commit dabb12e into numpy:main Jul 18, 2023
@ngoldbaum ngoldbaum added 09 - Backport-Candidate PRs tagged should be backported 08 - Backport Used to tag backport PRs and removed 09 - Backport-Candidate PRs tagged should be backported 08 - Backport Used to tag backport PRs labels Jul 19, 2023
@charris charris added this to the 1.25.2 release milestone Jul 23, 2023
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Jul 24, 2023
@charris charris removed this from the 1.25.2 release milestone Jul 24, 2023
charris added a commit to charris/numpy that referenced this pull request Jul 26, 2023
In numpygh-22449 `descr` was renamed `dtype`, which broke the build as
numpygh-24211 decrefed the old variable to fix a reference leak. This
bug slipped in because numpygh-22449 was not retested after the merge.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants