File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -2466,6 +2466,9 @@ PyArray_FromArrayAttr_int(
2466
2466
2467
2467
if (new == NULL ) {
2468
2468
if (npy_ma_str_array_err_msg_substr == NULL ) {
2469
+ Py_DECREF (array_meth );
2470
+ Py_DECREF (args );
2471
+ Py_DECREF (kwargs );
2469
2472
return NULL ;
2470
2473
}
2471
2474
PyObject * type , * value , * traceback ;
@@ -2481,6 +2484,7 @@ PyArray_FromArrayAttr_int(
2481
2484
"__array__ should implement 'dtype' and "
2482
2485
"'copy' keywords" , 1 ) < 0 ) {
2483
2486
Py_DECREF (str_value );
2487
+ Py_DECREF (array_meth );
2484
2488
Py_DECREF (args );
2485
2489
Py_DECREF (kwargs );
2486
2490
return NULL ;
@@ -2490,6 +2494,7 @@ PyArray_FromArrayAttr_int(
2490
2494
new = PyObject_Call (array_meth , args , kwargs );
2491
2495
if (new == NULL ) {
2492
2496
Py_DECREF (str_value );
2497
+ Py_DECREF (array_meth );
2493
2498
Py_DECREF (args );
2494
2499
Py_DECREF (kwargs );
2495
2500
return NULL ;
@@ -2500,15 +2505,16 @@ PyArray_FromArrayAttr_int(
2500
2505
}
2501
2506
if (new == NULL ) {
2502
2507
PyErr_Restore (type , value , traceback );
2508
+ Py_DECREF (array_meth );
2503
2509
Py_DECREF (args );
2504
2510
Py_DECREF (kwargs );
2505
2511
return NULL ;
2506
2512
}
2507
2513
}
2508
2514
2515
+ Py_DECREF (array_meth );
2509
2516
Py_DECREF (args );
2510
2517
Py_DECREF (kwargs );
2511
- Py_DECREF (array_meth );
2512
2518
2513
2519
if (!PyArray_Check (new )) {
2514
2520
PyErr_SetString (PyExc_ValueError ,
Original file line number Diff line number Diff line change @@ -8492,6 +8492,25 @@ def __array__(self, dtype=None):
8492
8492
"and 'copy' keywords" )):
8493
8493
np .array (a , copy = False )
8494
8494
8495
+ @pytest .mark .skipif (not HAS_REFCOUNT , reason = "Python lacks refcounts" )
8496
+ def test__array__reference_leak (self ):
8497
+ class NotAnArray :
8498
+ def __array__ (self ):
8499
+ raise NotImplementedError ()
8500
+
8501
+ x = NotAnArray ()
8502
+
8503
+ refcount = sys .getrefcount (x )
8504
+
8505
+ try :
8506
+ np .array (x )
8507
+ except NotImplementedError :
8508
+ pass
8509
+
8510
+ gc .collect ()
8511
+
8512
+ assert refcount == sys .getrefcount (x )
8513
+
8495
8514
@pytest .mark .parametrize (
8496
8515
"arr" , [np .ones (()), np .arange (81 ).reshape ((9 , 9 ))])
8497
8516
@pytest .mark .parametrize ("order1" , ["C" , "F" , None ])
You can’t perform that action at this time.
0 commit comments