Skip to content

Commit 8ebd3b4

Browse files
authored
Merge pull request #72 from PDAL/issue-71
Don't leak input arrays.
2 parents 6a43e27 + 0ccf6ae commit 8ebd3b4

File tree

3 files changed

+11
-22
lines changed

3 files changed

+11
-22
lines changed

pdal/PyPipeline.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ Pipeline::Pipeline(std::string const& json, std::vector<Array*> arrays) :
9999
};
100100

101101
r.setIncrementer(incrementer);
102-
PyObject* parray = (PyObject*)array->getPythonArray();
103-
if (!parray)
104-
throw pdal_error("array was none!");
105-
106102
roots[0]->setInput(r);
107103
}
108104

pdal/libpdalpython.pyx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,28 +93,21 @@ def getDimensions():
9393

9494
cdef class PyPipeline:
9595
cdef Pipeline *thisptr # hold a c++ instance which we're wrapping
96-
96+
cdef vector[Array *] c_arrays;
9797

9898
def __cinit__(self, unicode json, list arrays=None):
9999
cdef char* x = NULL
100-
cdef Py_ssize_t n_arrays;
101-
if arrays:
102-
n_arrays = len(arrays)
103-
104-
cdef vector[Array*] c_arrays;
105-
cdef np.ndarray np_array;
106-
cdef Array* a
107100

108101
if arrays is not None:
109102
for array in arrays:
110-
a = new Array(array)
111-
c_arrays.push_back(a)
112-
113-
self.thisptr = new Pipeline(json.encode('UTF-8'), c_arrays)
103+
self.c_arrays.push_back(new Array(array))
104+
self.thisptr = new Pipeline(json.encode('UTF-8'), self.c_arrays)
114105
else:
115106
self.thisptr = new Pipeline(json.encode('UTF-8'))
116107

117108
def __dealloc__(self):
109+
for array in self.c_arrays:
110+
del array
118111
del self.thisptr
119112

120113
property pipeline:

pdal/test/PythonFilterTest.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -682,10 +682,10 @@ TEST(PLangTest, PLangTest_aliases)
682682
"def yow(ins,outs):\n"
683683
" \n"
684684
" #print ins['X']\n"
685-
" #print ins['prefix.X']\n"
685+
" #print ins['prefix_X']\n"
686686
" \n"
687687
" X = ins['X']\n"
688-
" prefixX = ins['prefix.X']\n"
688+
" prefixX = ins['prefix_X']\n"
689689
" \n"
690690
" #print X\n"
691691
" #print prefixX\n"
@@ -697,19 +697,19 @@ TEST(PLangTest, PLangTest_aliases)
697697
" #print prefixY\n"
698698
" \n"
699699
" outs['Y'] = Y\n"
700-
" outs['prefix.Y'] = prefixY\n"
700+
" outs['prefix_Y'] = prefixY\n"
701701
" \n"
702702
" #print outs['Y']\n"
703-
" #print outs['prefix.Y']\n"
703+
" #print outs['prefix_Y']\n"
704704
" return True\n"
705705
;
706706

707707
PointTable table;
708708
table.layout()->registerDim(Dimension::Id::X);
709709
table.layout()->registerDim(Dimension::Id::Y);
710-
Dimension::Id prefixX = table.layout()->assignDim("prefix.X",
710+
Dimension::Id prefixX = table.layout()->assignDim("prefix_X",
711711
Dimension::Type::Double);
712-
Dimension::Id prefixY = table.layout()->assignDim("prefix.Y",
712+
Dimension::Id prefixY = table.layout()->assignDim("prefix_Y",
713713
Dimension::Type::Double);
714714
PointViewPtr view(new PointView(table));
715715
view->setField(Dimension::Id::X, 0, 1);

0 commit comments

Comments
 (0)