Skip to content

Commit a69b248

Browse files
committed
Fix memory leak in Pipeline.{arrays,meshes} properties
1 parent 1c77b7a commit a69b248

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

pdal/libpdalpython.pyx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# cython: c_string_type=unicode, c_string_encoding=utf8
33

44
import json
5+
from cpython.ref cimport Py_DECREF
56
from libcpp.vector cimport vector
67
from libcpp.string cimport string
78
from libc.stdint cimport int64_t
@@ -116,11 +117,11 @@ cdef class Pipeline:
116117

117118
property arrays:
118119
def __get__(self):
119-
return [<np.ndarray>a for a in self._executor.getArrays()]
120+
return self._vector_to_list(self._executor.getArrays())
120121

121122
property meshes:
122123
def __get__(self):
123-
return [<np.ndarray>a for a in self._executor.getMeshes()]
124+
return self._vector_to_list(self._executor.getMeshes())
124125

125126
def execute(self):
126127
return self._executor.execute()
@@ -143,3 +144,10 @@ cdef class Pipeline:
143144
np.stack((array["X"], array["Y"], array["Z"]), 1),
144145
[("triangle", np.stack((mesh["A"], mesh["B"], mesh["C"]), 1))],
145146
)
147+
148+
cdef _vector_to_list(self, vector[np.PyArrayObject*] arrays):
149+
output = []
150+
for array in arrays:
151+
output.append(<object>array)
152+
Py_DECREF(output[-1])
153+
return output

0 commit comments

Comments
 (0)