File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
numpy/core/src/multiarray Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 14
14
static void
15
15
array_dlpack_deleter (DLManagedTensor * self )
16
16
{
17
+ /*
18
+ * Leak the pyobj if not initialized. This can happen if we are running
19
+ * exit handlers that are destructing c++ objects with residual (owned)
20
+ * PyObjects stored in them after the Python runtime has already been
21
+ * terminated.
22
+ */
23
+ if (!Py_IsInitialized ()) {
24
+ return ;
25
+ }
26
+
27
+ PyGILState_STATE state = PyGILState_Ensure ();
28
+
17
29
PyArrayObject * array = (PyArrayObject * )self -> manager_ctx ;
18
30
// This will also free the shape and strides as it's one allocation.
19
31
PyMem_Free (self );
20
32
Py_XDECREF (array );
33
+
34
+ PyGILState_Release (state );
21
35
}
22
36
23
37
/* This is exactly as mandated by dlpack */
You can’t perform that action at this time.
0 commit comments