Memory leak in RGB2Lab

asked 2020-08-03 04:49:44 -0600

boaz001 gravatar image

updated 2020-08-04 04:03:50 -0600

There is a memory leak when using RBG2Lab. Is this an issue with OpenCV? The version is 3.4.11.

// lab.cpp
#include <opencv2/imgproc/imgproc.hpp>

int main()
{
  cv::Mat in = cv::Mat::zeros(1, 1, CV_8UC3);
  cv::Mat lab;
  cv::cvtColor(in, lab, CV_RGB2Lab);
}

Compile: g++ `pkg-config --libs --cflags opencv` lab.cpp

Run: valgrind --leak-check=full a.out

Output:

==2689== Memcheck, a memory error detector
==2689== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==2689== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info
==2689== Command: lab
==2689== 
==2689== 
==2689== HEAP SUMMARY:
==2689==     in use at exit: 4,716,918 bytes in 321 blocks
==2689==   total heap usage: 5,506 allocs, 5,185 frees, 5,396,766 bytes allocated
==2689== 
==2689== 16,456 bytes in 1 blocks are possibly lost in loss record 101 of 109
==2689==    at 0x4A08178: malloc (vg_replace_malloc.c:298)
==2689==    by 0x93164D0: cv::fastMalloc(unsigned long) (alloc.cpp:150)
==2689==    by 0x76678CE: allocSingleton<float> (private.hpp:153)
==2689==    by 0x76678CE: splineBuild(cv::softfloat const*, unsigned long) [clone .constprop.37] (color_lab.cpp:22)
==2689==    by 0x7669300: cv::initLabTabs() (color_lab.cpp:1221)
==2689==    by 0x7679DD4: RGB2Lab_b (color_lab.cpp:1547)
==2689==    by 0x7679DD4: cv::hal::cvtBGRtoLab(unsigned char const*, unsigned long, unsigned char*, unsigned long, int, int, int, int, bool, bool, bool) (color_lab.cpp:4176)
==2689==    by 0x767F4AC: cv::cvtColorBGR2Lab(cv::_InputArray const&, cv::_OutputArray const&, bool, bool) (color_lab.cpp:4668)
==2689==    by 0x76DDE71: cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int) (color.cpp:270)
==2689==    by 0x400B5C: main (in a.out)
==2689== 
==2689== 16,456 bytes in 1 blocks are possibly lost in loss record 102 of 109
==2689==    at 0x4A08178: malloc (vg_replace_malloc.c:298)
==2689==    by 0x93164D0: cv::fastMalloc(unsigned long) (alloc.cpp:150)
==2689==    by 0x76678CE: allocSingleton<float> (private.hpp:153)
==2689==    by 0x76678CE: splineBuild(cv::softfloat const*, unsigned long) [clone .constprop.37] (color_lab.cpp:22)
==2689==    by 0x76695D4: cv::initLabTabs() (color_lab.cpp:1231)
==2689==    by 0x7679DD4: RGB2Lab_b (color_lab.cpp:1547)
==2689==    by 0x7679DD4: cv::hal::cvtBGRtoLab(unsigned char const*, unsigned long, unsigned char*, unsigned long, int, int, int, int, bool, bool, bool) (color_lab.cpp:4176)
==2689==    by 0x767F4AC: cv::cvtColorBGR2Lab(cv::_InputArray const&, cv::_OutputArray const&, bool, bool) (color_lab.cpp:4668)
==2689==    by 0x76DDE71: cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int) (color.cpp:270)
==2689==    by 0x400B5C: main (in a.out)
==2689== 
==2689== 16,456 bytes in 1 blocks are possibly lost in loss record 103 of 109
==2689==    at 0x4A08178: malloc (vg_replace_malloc.c:298)
==2689==    by 0x93164D0: cv::fastMalloc(unsigned long) (alloc.cpp:150)
==2689==    by 0x76678CE: allocSingleton<float> (private.hpp:153)
==2689==    by 0x76678CE: splineBuild(cv::softfloat const*, unsigned long) [clone .constprop.37] (color_lab.cpp:22)
==2689==    by 0x76695E5: cv::initLabTabs() (color_lab.cpp:1232)
==2689==    by 0x7679DD4: RGB2Lab_b (color_lab.cpp:1547)
==2689==    by 0x7679DD4: cv::hal::cvtBGRtoLab(unsigned char const*, unsigned long, unsigned char*, unsigned long, int, int, int, int, bool, bool, bool) (color_lab.cpp:4176)
==2689==    by 0x767F4AC: cv::cvtColorBGR2Lab(cv ...
(more)
edit retag flag offensive close merge delete

Comments

os ? can you check cv::getBuildInformation() and see, which hardware optimizations are enabled ?

can you loop that say, 100x, and see, if it's progressive ? (most likely, your code triggered loading a ton of openCL kernels or similar, which won't be cleaned up, that's the job of the os)

berak gravatar imageberak ( 2020-08-03 05:58:54 -0600 )edit
1

The OS is CentOS 6.10. It is not progressive. cv::getBuildInformation() output added to the question.

boaz001 gravatar imageboaz001 ( 2020-08-03 10:03:15 -0600 )edit
1

I've added the valgrind output with debug info enabled, this shows a function initLabTabs() in color_lab.cpp this function allocates (static) variables which are never freed, but this seems to be intentional. I think there is something wrong with the valgrind suppressions on my side.

boaz001 gravatar imageboaz001 ( 2020-08-04 06:15:34 -0600 )edit

but this seems to be intentional

i'd say so, too.

I think there is something wrong with the valgrind suppressions on my side.

hmmmm

berak gravatar imageberak ( 2020-08-04 06:26:28 -0600 )edit