resize memory leak (minor)

asked 2016-04-17 07:45:33 -0500

mousomer gravatar image

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 ...
(more)
edit retag flag offensive close merge delete