summaryrefslogtreecommitdiff
path: root/pcl
diff options
context:
space:
mode:
authorLars Buitinck <l.buitinck@esciencecenter.nl>2014-07-07 17:31:16 +0200
committerLars Buitinck <l.buitinck@esciencecenter.nl>2014-07-07 17:31:16 +0200
commit4ee7461b77628d9677649d035b5cf03062c9ae0b (patch)
treec38a0a122df40e3312532280547bc33cc6a4a275 /pcl
parent6c1bc31862e5e66b27d595085c53721db55864cc (diff)
fix segfault and memory leak in OctreePointCloudSearch
This is the segfault reported in #28. __cinit__ unconditionally calls its base class version, so two objects got allocated and one of them was leaked. Fixed by moving the actual allocation to __init__. Similarly, __dealloc__ would call its base class version and a "double delete" would follow. Fixed by removing the child class's __dealloc__, and set self.me to NULL explicitly in OctreePointCloud.__dealloc__ for added safety.
Diffstat (limited to 'pcl')
-rw-r--r--pcl/_pcl.pyx15
1 files changed, 8 insertions, 7 deletions
diff --git a/pcl/_pcl.pyx b/pcl/_pcl.pyx
index 8b7d6a4..ee1c2cc 100644
--- a/pcl/_pcl.pyx
+++ b/pcl/_pcl.pyx
@@ -566,17 +566,21 @@ cdef class OctreePointCloud:
Octree pointcloud
"""
cdef cpp.OctreePointCloud_t *me
-
+
def __cinit__(self, double resolution):
+ self.me = NULL
+ if resolution <= 0.:
+ raise ValueError("Expected resolution > 0., got %r" % resolution)
+
+ def __init__(self, double resolution):
"""
Constructs octree pointcloud with given resolution at lowest octree level
"""
- if resolution <= 0.:
- raise ValueError("Expected resolution > 0., got %r" % resolution)
self.me = new cpp.OctreePointCloud_t(resolution)
-
+
def __dealloc__(self):
del self.me
+ self.me = NULL # just to be sure
def set_input_cloud(self, PointCloud pc):
"""
@@ -639,9 +643,6 @@ cdef class OctreePointCloudSearch(OctreePointCloud):
"""
self.me = <cpp.OctreePointCloud_t*> new cpp.OctreePointCloudSearch_t(resolution)
- def __dealloc__(self):
- del self.me
-
def radius_search (self, point, double radius, unsigned int max_nn = 0):
"""
Search for all neighbors of query point that are within a given radius.