Skip to content

BUG: Fix a reference count leak in npy_find_descr_for_scalar. #27672

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
Oct 30, 2024

Conversation

charris
Copy link
Member

@charris charris commented Oct 30, 2024

Backport of #27666.

The reference count for common->singleton is incremented twice, when it should only be incremented once.

This leak was found when running Google's tests with NumPy 2.1.2, and appears to be a new leak as of NumPy 2.1, probably introduced in 1cb4044.

In particular, this test:
https://github.com/protocolbuffers/protobuf/blob/6cb71402940c6645e49959dfc915f16f4d2e6c20/python/google/protobuf/internal/numpy/numpy_test.py#L67 runs in Py_DEBUG mode and verifies that the total reference count before and after various test cases is unchanged. The same test case has found other NumPy reference count leaks in the past and it may be sensible to add something similar to NumPy's own test suite.

The reference count for common->singleton is incremented twice, when it
should only be incremented once.

This leak was found when running Google's tests with NumPy 2.1.2, and
appears to be a new leak as of NumPy 2.1, probably introduced in
numpy@1cb4044.

In particular, this test:
https://github.com/protocolbuffers/protobuf/blob/6cb71402940c6645e49959dfc915f16f4d2e6c20/python/google/protobuf/internal/numpy/numpy_test.py#L67
runs in Py_DEBUG mode and verifies that the total reference count before
and after various test cases is unchanged. The same test case has found
other NumPy reference count leaks in the past and it may be sensible to
add something similar to NumPy's own test suite.
@charris charris added 00 - Bug 08 - Backport Used to tag backport PRs labels Oct 30, 2024
@charris charris added this to the 2.1.3 release milestone Oct 30, 2024
@charris charris merged commit daa8699 into numpy:maintenance/2.1.x Oct 30, 2024
65 checks passed
@charris charris deleted the backport-27666 branch October 30, 2024 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00 - Bug 08 - Backport Used to tag backport PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants