Skip to content

Fix elem_dtype reference leak in conv_vlen2ndarray - #2991

Open
barlowa124 wants to merge 1 commit into
h5py:masterfrom
barlowa124:fix-vlen-elem-dtype-refleak-2839
Open

barlowa124 wants to merge 1 commit into
h5py:masterfrom
barlowa124:fix-vlen-elem-dtype-refleak-2839

Conversation

@barlowa124

Copy link
Copy Markdown

Fixes #2839.

Reading a variable-length dataset leaks one reference on the element
dtype for every element converted. A 50-item vlen-int dataset read
ten times leaves 500 extra references on np.dtype('int64').

The leak is in conv_vlen2ndarray (h5py/_conv.templ.pyx), which
calls Py_INCREF(elem_dtype) for each element. That argument is
borrowed, and none of the output paths consume the incref:
PyArray_SimpleNewFromData, np.frombuffer, and np.empty plus
memcpy each obtain their own dtype reference.

This drops the unbalanced incref. Refcounts stay flat across
repeated reads and returned arrays are unchanged.

TestVlen gains a regression test asserting the element dtype
refcount does not grow across repeated vlen reads. The vlen
selections of test_dtype.py and test_dataset.py pass here.
A news fragment is included.

@codecov

codecov Bot commented Oct 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.51%. Comparing base (0f9cbe7) to head (a5cc838).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2991   +/-   ##
=======================================
  Coverage   90.51%   90.51%           
=======================================
  Files          16       16           
  Lines        2551     2551           
=======================================
  Hits         2309     2309           
  Misses        242      242           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unbalanced Py_INCREF(elem_dtype) in vlen conversion

1 participant