Skip to content

Commit ea9e545

Browse files
committed
Change Pipeline._inputs vector of raw Array pointers to shared_ptr to prevent mem leak on copy
1 parent c1d0328 commit ea9e545

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

pdal/PyPipeline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void readPipeline(PipelineExecutor* executor, std::string json)
5757
}
5858

5959

60-
void addArrayReaders(PipelineExecutor* executor, std::vector<Array*> arrays)
60+
void addArrayReaders(PipelineExecutor* executor, std::vector<std::shared_ptr<Array>> arrays)
6161
{
6262
// Make the symbols in pdal_base global so that they're accessible
6363
// to PDAL plugins. Python dlopen's this extension with RTLD_LOCAL,

pdal/PyPipeline.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace python
4646
class Array;
4747

4848
void readPipeline(PipelineExecutor* executor, std::string json);
49-
void addArrayReaders(PipelineExecutor* executor, std::vector<Array*> arrays);
49+
void addArrayReaders(PipelineExecutor* executor, std::vector<std::shared_ptr<Array>> arrays);
5050
PyArrayObject* viewToNumpyArray(PointViewPtr view);
5151
PyArrayObject* meshToNumpyArray(const TriangularMesh* mesh);
5252
std::vector<PyArrayObject*> getArrays(const PipelineExecutor* executor);

pdal/libpdalpython.pyx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ from types import SimpleNamespace
66

77
from cpython.ref cimport Py_DECREF
88
from libcpp cimport bool
9+
from libcpp.memory cimport make_shared, shared_ptr
910
from libcpp.string cimport string
1011
from libcpp.vector cimport vector
1112

@@ -72,7 +73,7 @@ def infer_writer_driver(driver):
7273

7374
cdef extern from "PyArray.hpp" namespace "pdal::python":
7475
cdef cppclass Array:
75-
Array(np.ndarray) except +
76+
Array(np.PyArrayObject*) except +
7677

7778

7879
cdef extern from "pdal/PipelineExecutor.hpp" namespace "pdal":
@@ -91,14 +92,14 @@ cdef extern from "pdal/PipelineExecutor.hpp" namespace "pdal":
9192

9293
cdef extern from "PyPipeline.hpp" namespace "pdal::python":
9394
void readPipeline(PipelineExecutor*, string) except +
94-
void addArrayReaders(PipelineExecutor*, vector[Array *]) except +
95+
void addArrayReaders(PipelineExecutor*, vector[shared_ptr[Array]]) except +
9596
vector[np.PyArrayObject*] getArrays(const PipelineExecutor*) except +
9697
vector[np.PyArrayObject*] getMeshes(const PipelineExecutor*) except +
9798

9899

99100
cdef class Pipeline:
100101
cdef PipelineExecutor* _executor
101-
cdef vector[Array*] _inputs
102+
cdef vector[shared_ptr[Array]] _inputs
102103

103104
def __dealloc__(self):
104105
self.inputs = []
@@ -116,7 +117,7 @@ cdef class Pipeline:
116117
def inputs(self, ndarrays):
117118
self._inputs.clear()
118119
for ndarray in ndarrays:
119-
self._inputs.push_back(new Array(ndarray))
120+
self._inputs.push_back(make_shared[Array](<np.PyArrayObject*>ndarray))
120121
self._delete_executor()
121122

122123
@property

0 commit comments

Comments
 (0)