Skip to content
This repository was archived by the owner on Dec 30, 2023. It is now read-only.

Commit 4ee7461

Browse files
committed
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.
1 parent 6c1bc31 commit 4ee7461

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

pcl/_pcl.pyx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -566,17 +566,21 @@ cdef class OctreePointCloud:
566566
Octree pointcloud
567567
"""
568568
cdef cpp.OctreePointCloud_t *me
569-
569+
570570
def __cinit__(self, double resolution):
571+
self.me = NULL
572+
if resolution <= 0.:
573+
raise ValueError("Expected resolution > 0., got %r" % resolution)
574+
575+
def __init__(self, double resolution):
571576
"""
572577
Constructs octree pointcloud with given resolution at lowest octree level
573578
"""
574-
if resolution <= 0.:
575-
raise ValueError("Expected resolution > 0., got %r" % resolution)
576579
self.me = new cpp.OctreePointCloud_t(resolution)
577-
580+
578581
def __dealloc__(self):
579582
del self.me
583+
self.me = NULL # just to be sure
580584

581585
def set_input_cloud(self, PointCloud pc):
582586
"""
@@ -639,9 +643,6 @@ cdef class OctreePointCloudSearch(OctreePointCloud):
639643
"""
640644
self.me = <cpp.OctreePointCloud_t*> new cpp.OctreePointCloudSearch_t(resolution)
641645

642-
def __dealloc__(self):
643-
del self.me
644-
645646
def radius_search (self, point, double radius, unsigned int max_nn = 0):
646647
"""
647648
Search for all neighbors of query point that are within a given radius.

0 commit comments

Comments
 (0)