Skip to content

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

Merged
charris merged 1 commit into
numpy:maintenance/2.1.xfrom
charris:backport-27666
Oct 30, 2024
Merged

charris merged 1 commit into
numpy:maintenance/2.1.xfrom
charris:backport-27666

Conversation

@charris

@charris charris commented Oct 30, 2024

Copy link
Copy Markdown
Member

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
@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