c++algorithmlidar

C++ ICP Algorithm Memory Leak


I discovered a memory leak issue while performing the c++ 2d lidar iterative closest point algorithm.

https://github.com/mobilerobotics1111/Lidar_ICP_2d/blob/71ebf795b560cde2865aba121dc387c2759d4f36/ICP_Test1/NN.h#L16 The link above is the source code where the problem is suspected. There is a class pointer nested within the class.

~Kdnode() {
        if (this->left){
            this->left->~Kdnode();
            delete this->left;
            this->left = NULL;
        }
        if (this->right){
            this->right->~Kdnode();
            delete this->right;
            this->right = NULL;
        }
    }

I tried the above but it doesn't work. If I keep the program on, the memory usage keeps increasing.


Solution

  • https://github.com/thithin-ent/Lidar_ICP_2d

    This is original ICP source. And I replaced the kdtree source inside ICP.

    https://github.com/gishi523/kd-tree/blob/master/kdtree.h

    You can solve the memory leak by replacing it with the kdtree source above. Original source kdtree is not good.