8000 BUG: Fix reference leak in niche user old user dtypes · numpy/numpy@856eb95 · GitHub
[go: up one dir, main page]

Skip to content

Commit 856eb95

Browse files
sebergcharris
authored andcommitted
BUG: Fix reference leak in niche user old user dtypes
This was just a typo, add a test for the regression (checked that it triggered it). Closes gh-25949
1 parent f4e5508 commit 856eb95

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

numpy/core/src/multiarray/usertypes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ PyArray_RegisterDataType(PyArray_Descr *descr)
305305
NPY_DT_SLOTS(NPY_DTYPE(descr))->get_clear_loop = (
306306
&npy_get_clear_void_and_legacy_user_dtype_loop);
307307
/* Also use the void zerofill since there may be objects */
308-
NPY_DT_SLOTS(NPY_DTYPE(descr))->get_clear_loop = (
309-
&npy_get_zerofill_void_and_legacy_user_dtype_loop);
308+
NPY_DT_SLOTS(NPY_DTYPE(descr))->get_fill_zero_loop = (
309+
(get_traverse_loop_function *)&npy_get_zerofill_void_and_legacy_user_dtype_loop);
310310
}
311311

312312
return typenum;

numpy/core/tests/test_dtype.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,6 +1848,13 @@ class mytype:
18481848
# unnecessary restriction, but one that has been around forever:
18491849
assert np.dtype(mytype) == np.dtype("O")
18501850

1851+
if HAS_REFCOUNT:
1852+
# Create an array and test that memory gets cleaned up (gh-25949)
1853+
o = object()
1854+
a = np.array([o], dtype=dt)
1855+
del a
1856+
assert sys.getrefcount(o) == 2
1857+
18511858
def test_custom_structured_dtype_errors(self):
18521859
class mytype:
18531860
pass

0 commit comments

Comments
 (0)
0