Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

resize memory leak (minor)

I found a small memory leak through valgrind. I comes from the resize function. This is the simplest code generating it:

    cv::Mat f_out, f_in= cv::Mat(100, 100, CV_8U, 1); // nrows, ncols
    cv::Size c_size(200, 200);
    cv::resize(f_in, f_out, c_size, 0, 0, cv::INTER_LINEAR);

OpenCV is 3.0.0; the system is Centos 6.0;, with gcc 4.47 and glibc version 4.4.7 20120313 (Red Hat 4.4.7-11). I tried playing with it:

int main(int agrc, char** argv)
{
    int kk=10000;
    for (int k=0; k<kk; ++k)
    {
        int tt=(int) (300 + 100*sin(0.0001*k));
        int vv=(int) (3 + 1*sin(0.0001*k));
        cv::Mat f_out, f_in= cv::Mat(tt, tt, CV_8U, vv); // nrows, ncols
        cv::Size c_size(tt/2, tt/2);
        cv::resize(f_in, f_out, c_size, 0, 0, cv::INTER_LINEAR);
    }
return 0;
}

and I still get exactly the same 288 bytes reported as "still reachable" by Valgrind:

==30655== HEAP SUMMARY:
==30655==     in use at exit: 288 bytes in 7 blocks
==30655==   total heap usage: 50,175 allocs, 50,168 frees, 1,529,006,039 bytes allocated
==30655== 
==30655== Searching for pointers to 7 not-freed blocks
==30655== Checked 1,319,256 bytes
==30655== 
==30655== 8 bytes in 1 blocks are still reachable in loss record 1 of 7
==30655==    at 0x4A07E85: operator new(unsigned long) (vg_replace_malloc.c:333)
==30655==    by 0x4CF6FE0: std::vector<cv::TLSDataContainer*, std::allocator<cv::TLSDataContainer*> >::_M_insert_aux(__gnu_cxx::__normal_iterator<cv::TLSDataContainer**, std::vector<cv::TLSDataContainer*, std::allocator<cv::TLSDataContainer*> > >, cv::TLSDataContainer* const&) (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0)
==30655==    by 0x4CF715D: cv::TLSDataContainer::TLSDataContainer() (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0)
==30655==    by 0x4CF71D4: cv::getCoreTlsData() (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0)
==30655==    by 0x4CF755C: cv::ipp::useIPP() (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0)
==30655==    by 0x5909C2C: cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int) (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_imgproc.so.3.0.0)
==30655==    by 0x400C45: main (resize_test.cpp:28)
==30655== 
==30655== 16 bytes in 1 blocks are still reachable in loss record 2 of 7
==30655==    at 0x4A07E85: operator new(unsigned long) (vg_replace_malloc.c:333)
==30655==    by 0x4CF71C9: cv::getCoreTlsData() (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0)
==30655==    by 0x4CF755C: cv::ipp::useIPP() (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0)
==30655==    by 0x5909C2C: cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int) (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_imgproc.so.3.0.0)
==30655==    by 0x400C45: main (resize_test.cpp:28)
==30655== 
==30655== 24 bytes in 1 blocks are still reachable in loss record 3 of 7
==30655==    at 0x4A07E85: operator new(unsigned long) (vg_replace_malloc.c:333)
==30655==    by 0x4CF7411: cv::TLSDataContainer::getData() const (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0)
==30655==    by 0x4CF7564: cv::ipp::useIPP() (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0)
==30655==    by 0x5909C2C: cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int) (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_imgproc.so.3.0.0)
==30655==    by 0x400C45: main (resize_test.cpp:28)
==30655== 
==30655== 32 bytes in 1 blocks are still reachable in loss record 4 of 7
==30655==    at 0x4A07E85: operator new(unsigned long) (vg_replace_malloc.c:333)
==30655==    by 0x4CF5759: cv::getTLSContainerStorage() (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0)
==30655==    by 0x4CF70E4: cv::TLSDataContainer::TLSDataContainer() (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0)
==30655==    by 0x4CF71D4: cv::getCoreTlsData() (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0)
==30655==    by 0x4CF755C: cv::ipp::useIPP() (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0)
==30655==    by 0x5909C2C: cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int) (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_imgproc.so.3.0.0)
==30655==    by 0x400C45: main (resize_test.cpp:28)
==30655== 
==30655== 32 bytes in 1 blocks are still reachable in loss record 5 of 7
==30655==    at 0x4A07E85: operator new(unsigned long) (vg_replace_malloc.c:333)
==30655==    by 0x4CF552E: cv::TLSData<cv::CoreTLSData>::createDataInstance() const (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0)
==30655==    by 0x4CF733B: cv::TLSDataContainer::getData() const (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0)
==30655==    by 0x4CF7564: cv::ipp::useIPP() (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0)
==30655==    by 0x5909C2C: cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int) (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_imgproc.so.3.0.0)
==30655==    by 0x400C45: main (resize_test.cpp:28)
==30655== 
==30655== 48 bytes in 1 blocks are still reachable in loss record 6 of 7
==30655==    at 0x4A07E85: operator new(unsigned long) (vg_replace_malloc.c:333)
==30655==    by 0x4CF56BF: cv::Mutex::Mutex() (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0)
==30655==    by 0x4CF5764: cv::getTLSContainerStorage() (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0)
==30655==    by 0x4CF70E4: cv::TLSDataContainer::TLSDataContainer() (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0)
==30655==    by 0x4CF71D4: cv::getCoreTlsData() (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0)
==30655==    by 0x4CF755C: cv::ipp::useIPP() (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0)
==30655==    by 0x5909C2C: cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int) (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_imgproc.so.3.0.0)
==30655==    by 0x400C45: main (resize_test.cpp:28)
==30655== 
==30655== 128 bytes in 1 blocks are still reachable in loss record 7 of 7
==30655==    at 0x4A07E85: operator new(unsigned long) (vg_replace_malloc.c:333)
==30655==    by 0x4CF6595: std::vector<void*, std::allocator<void*> >::reserve(unsigned long) (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0)
==30655==    by 0x4CF743B: cv::TLSDataContainer::getData() const (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0)
==30655==    by 0x4CF7564: cv::ipp::useIPP() (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_core.so.3.0.0)
==30655==    by 0x5909C2C: cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int) (in ~/Install/opencv/opencv-3.0.0/build/lib/libopencv_imgproc.so.3.0.0)
==30655==    by 0x400C45: main (resize_test.cpp:28)
==30655== 
==30655== LEAK SUMMARY:
==30655==    definitely lost: 0 bytes in 0 blocks
==30655==    indirectly lost: 0 bytes in 0 blocks
==30655==      possibly lost: 0 bytes in 0 blocks
==30655==    still reachable: 288 bytes in 7 blocks
==30655==         suppressed: 0 bytes in 0 blocks
==30655==