Skip to content

Double free or corruption (out) error in framegrabber process #142

Closed
@robinbansal08

Description

@robinbansal08

I am using libo3d3xx as our project requires deployment of the codes over the camera.

I am getting strange runtime errors double free or corruption (out) error when using framegrabber function even with the simplest of the codes I tried as mentioned below. After various rounds of testing I found, that this error is quite inconsistent and disappears with commenting out segments of the code which are not even being used or called upon by any function calls (for example, function int getSavedPCD_(int id, pcl::PointCloud<pcl::PointXYZI>::Ptr& cloud_xyzi) in the code (Code: test_1) mentioned below). Interestingly, when I cross compiled the code to run it over the camera O3D303, it runs successfully over it without any runtime error. It would be really helpful if you could provide your expert insight about this strange error.

I have installed libo3d3xx 0.7.7 version and using Ubuntu 18.04.

My compiler list:

ii  g++                                        4:7.4.0-1ubuntu2.3                               amd64        GNU C++ compiler
ii  g++-7                                      7.5.0-3ubuntu1~18.04                             amd64        GNU C++ compiler
ii  gcc                                        4:7.4.0-1ubuntu2.3                               amd64        GNU C compiler
ii  gcc-7                                      7.5.0-3ubuntu1~18.04                             amd64        GNU C compiler
ii  gfortran                                   4:7.4.0-1ubuntu2.3                               amd64        GNU Fortran 95 compiler
ii  gfortran-7                                 7.5.0-3ubuntu1~18.04                             amd64        GNU Fortran compiler
ii  libllvm6.0:amd64                           1:6.0-1ubuntu2                                   amd64        Modular compiler and toolchain technologies, runtime library
ii  libllvm9:amd64                             1:9-2~ubuntu18.04.2                              amd64        Modular compiler and toolchain technologies, runtime library
ii  libxkbcommon-dev:amd64                     0.8.2-1~ubuntu18.04.1                            amd64        library interface to the XKB compiler - development files
ii  libxkbcommon0:amd64                        0.8.2-1~ubuntu18.04.1                            amd64        library interface to the XKB compiler - shared library

My code looks like this:

Code: test_1

#include <iostream>
#include <memory>
#include <opencv2/opencv.hpp>
#include <pcl/io/pcd_io.h>
#include <pcl/point_cloud.h>
#include "o3d3xx_camera.h"
#include "o3d3xx_framegrabber.h"
#include "o3d3xx_image.h"

using namespace pcl;
using namespace pcl::io;
using namespace std;
using namespace cv;

#define BOLD    "\033[1m"
#define RESET   "\033[0m"
#define RED     "\033[31m"
#define GREEN   "\033[32m"
#define YELLOW  "\033[33m"
#define BLUE    "\033[34m"
#define MAGENTA "\033[35m"
#define CYAN    "\033[36m"
#define WHITE   "\033[37m"

string PCDFilenameBase;

int getSavedPCD_(int id, pcl::PointCloud<pcl::PointXYZI>::Ptr& cloud_xyzi)
{

    if (PCDFilenameBase.empty())
    {
        cout<<RED<<"PCDFilenameBase not set !!"<<endl;
        exit(-1);
    }
    std::string filename;

    filename = PCDFilenameBase + std::to_string(id) + ".pcd";

    if (pcl::io::loadPCDFile (filename, *cloud_xyzi) == -1) //load the file
    {
        cout<<RED<<"Error!! Couldn't read file"<<filename<<RESET<<endl;
        exit (-1);
    }
    cout<<GREEN<<"Loaded image "<<filename<<RESET<<"\n";
    return 1;
}

void testCapture(string camIP)
{

    o3d3xx::Camera::Ptr cam = std::make_shared<o3d3xx::Camera>(camIP);
    o3d3xx::ImageBuffer::Ptr img = std::make_shared<o3d3xx::ImageBuffer>();
    o3d3xx::FrameGrabber::Ptr fg = std::make_shared<o3d3xx::FrameGrabber>(cam, o3d3xx::IMG_AMP|o3d3xx::IMG_RDIS|o3d3xx::IMG_CART);
    o3d3xx::Logging::Init();
    fg->SWTrigger();
    if (! fg->WaitForFrame(img.get(), 1000))
    {
        std::cerr << "Timeout waiting for camera!" << std::endl;
        exit (-1);
    }
    cout<<"Captured pcd"<<endl;
}

int main(int argc, char** argv)
{
    testCapture("192.168.0.25");
    return 1;
}

I tried the following code over Ubuntu 18.04, I get runtime error as mentioned below:

WARNING: Logging before InitGoogleLogging() is written to STDERR
I0725 17:08:27.374589 23576 frame_grabber.cpp:72] Camera connection info: ip=192.168.0.25, port=50010
Captured pcd
double free or corruption (out)
Aborted (core dumped)

My debug result for the memory fault is:

==23597== Memcheck, a memory error detector
==23597== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==23597== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==23597== Command: ./createDatabase_v3
==23597== 
WARNING: Logging before InitGoogleLogging() is written to STDERR
I0725 17:19:59.649514 23597 frame_grabber.cpp:72] Camera connection info: ip=192.168.0.25, port=50010
Captured pcd
==23597== Invalid free() / delete / delete[] / realloc()
==23597==    at 0x4C30D3B: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==23597==    by 0x5507B1E: o3d3xx::ImageBuffer::~ImageBuffer() (in /usr/lib/libo3d3xx_image.so.0.7.7)
==23597==    by 0x13AEDE: void __gnu_cxx::new_allocator<o3d3xx::ImageBuffer>::destroy<o3d3xx::ImageBuffer>(o3d3xx::ImageBuffer*) (new_allocator.h:140)
==23597==    by 0x13ACDA: void std::allocator_traits<std::allocator<o3d3xx::ImageBuffer> >::destroy<o3d3xx::ImageBuffer>(std::allocator<o3d3xx::ImageBuffer>&, o3d3xx::ImageBuffer*) (alloc_traits.h:487)
==23597==    by 0x139DC2: std::_Sp_counted_ptr_inplace<o3d3xx::ImageBuffer, std::allocator<o3d3xx::ImageBuffer>, (__gnu_cxx::_Lock_policy)2>::_M_dispose() (shared_ptr_base.h:535)
==23597==    by 0x132029: std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() (shared_ptr_base.h:154)
==23597==    by 0x13104C: std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count() (shared_ptr_base.h:684)
==23597==    by 0x130B4F: std::__shared_ptr<o3d3xx::ImageBuffer, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr() (shared_ptr_base.h:1123)
==23597==    by 0x130B6B: std::shared_ptr<o3d3xx::ImageBuffer>::~shared_ptr() (shared_ptr.h:93)
==23597==    by 0x12E337: testCapture(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) (main.cpp:57)
==23597==    by 0x12E3EB: main (main.cpp:72)
==23597==  Address 0x15af8060 is 32 bytes inside a block of size 2,973,728 alloc'd
==23597==    at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==23597==    by 0x12EE52: Eigen::internal::handmade_aligned_malloc(unsigned long) (Memory.h:88)
==23597==    by 0x12EED6: Eigen::internal::aligned_malloc(unsigned long) (Memory.h:164)
==23597==    by 0x138480: Eigen::aligned_allocator<pcl::PointXYZI>::allocate(unsigned long, void const*) (Memory.h:742)
==23597==    by 0x137119: std::allocator_traits<Eigen::aligned_allocator<pcl::PointXYZI> >::allocate(Eigen::aligned_allocator<pcl::PointXYZI>&, unsigned long) (alloc_traits.h:301)
==23597==    by 0x1362F9: std::_Vector_base<pcl::PointXYZI, Eigen::aligned_allocator<pcl::PointXYZI> >::_M_allocate(unsigned long) (stl_vector.h:172)
==23597==    by 0x1352AB: std::vector<pcl::PointXYZI, Eigen::aligned_allocator<pcl::PointXYZI> >::_M_default_append(unsigned long) (vector.tcc:571)
==23597==    by 0x55096EE: o3d3xx::ImageBuffer::Organize() (in /usr/lib/libo3d3xx_image.so.0.7.7)
==23597==    by 0x52E87C6: o3d3xx::FrameGrabber::WaitForFrame(o3d3xx::ByteBuffer*, long, bool, bool) (in /usr/lib/libo3d3xx_framegrabber.so.0.7.7)
==23597==    by 0x12E2BE: testCapture(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) (main.cpp:61)
==23597==    by 0x12E3EB: main (main.cpp:72)
==23597== 
==23597== 
==23597== HEAP SUMMARY:
==23597==     in use at exit: 2,982,151 bytes in 189 blocks
==23597==   total heap usage: 5,973 allocs, 5,785 frees, 7,080,318 bytes allocated
==23597== 
==23597== 2,973,728 bytes in 1 blocks are possibly lost in loss record 183 of 183
==23597==    at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==23597==    by 0x12EE52: Eigen::internal::handmade_aligned_malloc(unsigned long) (Memory.h:88)
==23597==    by 0x12EED6: Eigen::internal::aligned_malloc(unsigned long) (Memory.h:164)
==23597==    by 0x138480: Eigen::aligned_allocator<pcl::PointXYZI>::allocate(unsigned long, void const*) (Memory.h:742)
==23597==    by 0x137119: std::allocator_traits<Eigen::aligned_allocator<pcl::PointXYZI> >::allocate(Eigen::aligned_allocator<pcl::PointXYZI>&, unsigned long) (alloc_traits.h:301)
==23597==    by 0x1362F9: std::_Vector_base<pcl::PointXYZI, Eigen::aligned_allocator<pcl::PointXYZI> >::_M_allocate(unsigned long) (stl_vector.h:172)
==23597==    by 0x1352AB: std::vector<pcl::PointXYZI, Eigen::aligned_allocator<pcl::PointXYZI> >::_M_default_append(unsigned long) (vector.tcc:571)
==23597==    by 0x55096EE: o3d3xx::ImageBuffer::Organize() (in /usr/lib/libo3d3xx_image.so.0.7.7)
==23597==    by 0x52E87C6: o3d3xx::FrameGrabber::WaitForFrame(o3d3xx::ByteBuffer*, long, bool, bool) (in /usr/lib/libo3d3xx_framegrabber.so.0.7.7)
==23597==    by 0x12E2BE: testCapture(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) (main.cpp:61)
==23597==    by 0x12E3EB: main (main.cpp:72)
==23597== 
==23597== LEAK SUMMARY:
==23597==    definitely lost: 0 bytes in 0 blocks
==23597==    indirectly lost: 0 bytes in 0 blocks
==23597==      possibly lost: 2,973,728 bytes in 1 blocks
==23597==    still reachable: 8,423 bytes in 188 blocks
==23597==         suppressed: 0 bytes in 0 blocks
==23597== Reachable blocks (those to which a pointer was found) are not shown.
==23597== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==23597== 
==23597== For counts of detected and suppressed errors, rerun with: -v
==23597== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)

To test further, I removed the function int getSavedPCD_(int id, pcl::PointCloud<pcl::PointXYZI>::Ptr& cloud_xyzi), and run the following mentioned code (Code: test_2), then I don't get any runtime error.

Code: test_2

#include <iostream>
#include <memory>
#include <opencv2/opencv.hpp>
#include <pcl/io/pcd_io.h>
#include <pcl/point_cloud.h>
#include "o3d3xx_camera.h"
#include "o3d3xx_framegrabber.h"
#include "o3d3xx_image.h"

using namespace pcl;
using namespace pcl::io;
using namespace std;
using namespace cv;

#define BOLD    "\033[1m"
#define RESET   "\033[0m"
#define RED     "\033[31m"
#define GREEN   "\033[32m"
#define YELLOW  "\033[33m"
#define BLUE    "\033[34m"
#define MAGENTA "\033[35m"
#define CYAN    "\033[36m"
#define WHITE   "\033[37m"

// NOTE: 
// funtion: int getSavedPCD_(int id, pcl::PointCloud<pcl::PointXYZI>::Ptr& cloud_xyzi) has been removed

void testCapture(string camIP)
{

    o3d3xx::Camera::Ptr cam = std::make_shared<o3d3xx::Camera>(camIP);
    o3d3xx::ImageBuffer::Ptr img = std::make_shared<o3d3xx::ImageBuffer>();
    o3d3xx::FrameGrabber::Ptr fg = std::make_shared<o3d3xx::FrameGrabber>(cam, o3d3xx::IMG_AMP|o3d3xx::IMG_RDIS|o3d3xx::IMG_CART);
    o3d3xx::Logging::Init();
    fg->SWTrigger();
    if (! fg->WaitForFrame(img.get(), 1000))
    {
        std::cerr << "Timeout waiting for camera!" << std::endl;
        exit (-1);
    }
    cout<<"Captured pcd"<<endl;
}

int main(int argc, char** argv)
{
    testCapture("192.168.0.25");
    return 1;
}

Output of the above code (Code: test_2), no runtime error occurred.

WARNING: Logging before InitGoogleLogging() is written to STDERR
I0725 17:30:03.503839 23650 frame_grabber.cpp:72] Camera connection info: ip=192.168.0.25, port=50010
Captured pcd

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions