Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Found a memory leak #16591

Closed
libaineu2004 opened this issue Feb 15, 2020 · 4 comments
Closed

Found a memory leak #16591

libaineu2004 opened this issue Feb 15, 2020 · 4 comments
Labels
duplicate incomplete needs reproducer Provide complete minimal reproducer with input data

Comments

@libaineu2004
Copy link

System information (version)
  • OpenCV => 4.2.0
  • Operating System / Platform => Windows 7 64 Bit
  • Compiler => Visual Studio 2017
Detailed description
Steps to reproduce

1.I use VS2017, C ++/MFC/Win32 project。When I quit the program, I found a memory leak。
Detected memory leaks!
Dumping objects ->
{377} normal block at 0x041259A8, 56 bytes long.
Data: < > 01 00 CD CD 00 00 00 00 00 00 00 00 00 00 00 00
{311} normal block at 0x04122DE8, 12 bytes long.
Data: 4F 70 65 6E 43 56 54 72 61 63 65 00
{310} normal block at 0x04131F48, 24 bytes long.
Data: < - > 01 00 00 00 E8 2D 12 04 00 00 00 00 00 00 00 00
{305} normal block at 0x040DE428, 128 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{304} normal block at 0x040DEC68, 128 bytes long.
Data: < > 00 00 00 00 CD CD CD CD CD CD CD CD CD CD CD CD
{303} normal block at 0x04123268, 8 bytes long.
Data: <,4 > 2C 34 12 04 00 00 00 00
{302} normal block at 0x04123100, 8 bytes long.
Data: < 4 > 1C 34 12 04 00 00 00 00
{301} normal block at 0x041233E8, 84 bytes long.
Data: < qb > 02 01 00 00 A8 85 71 62 00 00 00 00 CD CD CD CD
{300} normal block at 0x04120F90, 48 bytes long.
Data: < qb > 02 01 00 00 A8 85 71 62 00 00 00 00 CD CD CD CD

2.Then I used windbg.exe to debug and found the following information:
0:000> !heap -p -a 0x041259A8
address 041259a8 found in
_HEAP @ 40b0000
HEAP_ENTRY Size Prev Flags UserPtr UserSize - state
04125970 000f 0000 [00] 04125988 0005c - (busy)
77e93484 ntdll!RtlpCallInterceptRoutine+0x00000026
77e50a8a ntdll!RtlpAllocateHeapInternal+0x00055c8a
77dfadee ntdll!RtlAllocateHeap+0x0000003e
622ab4a5 ucrtbased!heap_alloc_dbg_internal+0x00000195
622ab2c6 ucrtbased!heap_alloc_dbg+0x00000036
622ada3a ucrtbased!_malloc_dbg+0x0000001a
622ae354 ucrtbased!malloc+0x00000014
*** WARNING: Unable to verify checksum for D:\My Resources\2-PartTime\SmartDispenser\SmartDispenser 2020.02.02\Debug\opencv_core420d.dll
*** ERROR: Symbol file could not be found. Defaulted to export symbols for D:\My Resources\2-PartTime\SmartDispenser\SmartDispenser 2020.02.02\Debug\opencv_core420d.dll -
5dbf7ed opencv_core420d!cv::SparseMat::ptr+0x00a38123
5cee65a opencv_core420d!cv::SparseMat::ptr+0x00966f90
5cee918 opencv_core420d!cv::SparseMat::ptr+0x0096724e
*** WARNING: Unable to verify checksum for D:\My Resources\2-PartTime\SmartDispenser\SmartDispenser 2020.02.02\Debug\opencv_imgproc420d.dll
*** ERROR: Symbol file could not be found. Defaulted to export symbols for D:\My Resources\2-PartTime\SmartDispenser\SmartDispenser 2020.02.02\Debug\opencv_imgproc420d.dll -
79e14fb3 opencv_imgproc420d!cvDrawContours+0x00f9eb8b
79b138bd opencv_imgproc420d!cvDrawContours+0x00c9d495
622c59df ucrtbased!_initterm+0x0000003f
7a0e90f7 opencv_imgproc420d!cvDrawContours+0x01272ccf
7a0e8fb9 opencv_imgproc420d!cvDrawContours+0x01272b91
7a0e93a3 opencv_imgproc420d!cvDrawContours+0x01272f7b
7a0e958f opencv_imgproc420d!cvDrawContours+0x01273167
77e31d36 ntdll!LdrxCallInitRoutine+0x00000016
77df5558 ntdll!LdrpCallInitRoutine+0x00000051
77e03edf ntdll!LdrpInitializeNode+0x00000133
77e04786 ntdll!LdrpInitializeGraphRecurse+0x0000005d
77e0479d ntdll!LdrpInitializeGraphRecurse+0x00000074
77e0479d ntdll!LdrpInitializeGraphRecurse+0x00000074
77e0479d ntdll!LdrpInitializeGraphRecurse+0x00000074
77e0479d ntdll!LdrpInitializeGraphRecurse+0x00000074
77e69472 ntdll!LdrpInitializeGraph+0x00000013
77e692b2 ntdll!LdrpInitializeProcess+0x00001cc2
77e11d21 ntdll!_LdrpInitialize+0x000000ba
77e11c11 ntdll!LdrInitializeThunk+0x00000011

0:000> !heap -p -a 0x041233E8
address 041233e8 found in
_HEAP @ 40b0000
HEAP_ENTRY Size Prev Flags UserPtr UserSize - state
041233b0 0012 0000 [00] 041233c8 00078 - (busy)
77e93484 ntdll!RtlpCallInterceptRoutine+0x00000026
77e50a8a ntdll!RtlpAllocateHeapInternal+0x00055c8a
77dfadee ntdll!RtlAllocateHeap+0x0000003e
622ab4a5 ucrtbased!heap_alloc_dbg_internal+0x00000195
622ab2c6 ucrtbased!heap_alloc_dbg+0x00000036
622ada3a ucrtbased!_malloc_dbg+0x0000001a
622ae354 ucrtbased!malloc+0x00000014
5dbf7ed opencv_core420d!cv::SparseMat::ptr+0x00a38123
5cef0ba opencv_core420d!cv::SparseMat::ptr+0x009679f0
5ce6570 opencv_core420d!cv::SparseMat::ptr+0x0095eea6
5cf53d5 opencv_core420d!cv::SparseMat::ptr+0x0096dd0b
5cf5465 opencv_core420d!cv::SparseMat::ptr+0x0096dd9b
5cf6eae opencv_core420d!cv::SparseMat::ptr+0x0096f7e4
5cfd155 opencv_core420d!cv::SparseMat::ptr+0x00975a8b
5cfd056 opencv_core420d!cv::SparseMat::ptr+0x0097598c
5cfd661 opencv_core420d!cv::SparseMat::ptr+0x00975f97
5cf603b opencv_core420d!cv::SparseMat::ptr+0x0096e971
5d2ca80 opencv_core420d!cv::SparseMat::ptr+0x009a53b6
5d259a2 opencv_core420d!cv::SparseMat::ptr+0x0099e2d8
5afe90b opencv_core420d!cv::SparseMat::ptr+0x00777241
5afecb5 opencv_core420d!cv::SparseMat::ptr+0x007775eb
5afe8b3 opencv_core420d!cv::SparseMat::ptr+0x007771e9
5986f2d opencv_core420d!cv::SparseMat::ptr+0x005ff863
622c59df ucrtbased!_initterm+0x0000003f
5dc17c7 opencv_core420d!cv::SparseMat::ptr+0x00a3a0fd
5dc1689 opencv_core420d!cv::SparseMat::ptr+0x00a39fbf
5dc1a73 opencv_core420d!cv::SparseMat::ptr+0x00a3a3a9
5dc1c5f opencv_core420d!cv::SparseMat::ptr+0x00a3a595
77e31d36 ntdll!LdrxCallInitRoutine+0x00000016
77df5558 ntdll!LdrpCallInitRoutine+0x00000051
77e03edf ntdll!LdrpInitializeNode+0x00000133
77e04786 ntdll!LdrpInitializeGraphRecurse+0x0000005d

3.What is the problem? How to deal with it?

@mshabunin
Copy link
Contributor

Please add minimal reproducer application.

BTW, your debug symbols looks broken.

@mshabunin mshabunin added incomplete needs reproducer Provide complete minimal reproducer with input data labels Feb 17, 2020
@libaineu2004
Copy link
Author

Please add minimal reproducer application.

BTW, your debug symbols looks broken.

ok. I try again,now info list:
Detected memory leaks!
Dumping objects ->
{375} normal block at 0x007E4B58, 56 bytes long.
Data: < > 01 00 CD CD 00 00 00 00 00 00 00 00 00 00 00 00
{309} normal block at 0x007F05D0, 12 bytes long.
Data: 4F 70 65 6E 43 56 54 72 61 63 65 00
{308} normal block at 0x007CAD90, 24 bytes long.
Data: < > 01 00 00 00 D0 05 7F 00 00 00 00 00 00 00 00 00
{303} normal block at 0x007FBA80, 128 bytes long.
Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{302} normal block at 0x007FB9C0, 128 bytes long.
Data: < > 00 00 00 00 CD CD CD CD CD CD CD CD CD CD CD CD
{301} normal block at 0x007F04F8, 8 bytes long.
Data: < { > 14 9E 7B 00 00 00 00 00
{300} normal block at 0x007F04B0, 8 bytes long.
Data: < { > 04 9E 7B 00 00 00 00 00
{299} normal block at 0x007B9DD0, 84 bytes long.
Data: < ? > 02 01 00 00 A8 85 3F 00 00 00 00 00 CD CD CD CD
{298} normal block at 0x007E1248, 48 bytes long.
Data: < ? > 02 01 00 00 A8 85 3F 00 00 00 00 00 CD CD CD CD
{191} normal block at 0x007CE5E0, 8 bytes long.
Data: 4C 6C 37 0F 01 CD CD CD
Object dump complete.
eax=00000000 ebx=00000000 ecx=00000002 edx=00000000 esi=777c2100 edi=777c20c0
eip=776dfcc2 esp=0030f4b4 ebp=0030f4d0 iopl=0 nv up ei pl zr na pe nc
cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00000246
ntdll!NtTerminateProcess+0x12:
776dfcc2 83c404 add esp,4
0:000> !heap -p -a 0x007E4B58
address 007e4b58 found in
_HEAP @ 770000
HEAP_ENTRY Size Prev Flags UserPtr UserSize - state
007e4b20 000f 0000 [00] 007e4b38 0005c - (busy)
7773d929 ntdll!RtlAllocateHeap+0x00000274
f1b4a5 ucrtbased!heap_alloc_dbg_internal+0x00000195
f1b2c6 ucrtbased!heap_alloc_dbg+0x00000036
f1da3a ucrtbased!_malloc_dbg+0x0000001a
f1e354 ucrtbased!malloc+0x00000014
*** WARNING: Unable to verify checksum for D:\My Resources\2-Part Time\SmartDispenser\SmartDispenser 2020.02.02\Debug\opencv_core420d.dll
c0af7ed opencv_core420d!operator new+0x0000000d
bfde65a opencv_core420d!cv::ipp::getIPPSingleton+0x0000006a
bfde918 opencv_core420d!cv::ipp::getIppFeatures+0x00000008
*** WARNING: Unable to verify checksum for D:\My Resources\2-Part Time\SmartDispenser\SmartDispenser 2020.02.02\Debug\opencv_imgproc420d.dll
d504fb3 opencv_imgproc420d!IppInitializer::IppInitializer+0x00000023
d2038bd opencv_imgproc420d!`dynamic initializer for 'ipp_initializer''+0x0000000d
f359df ucrtbased!_initterm+0x0000003f
d7d90f7 opencv_imgproc420d!dllmain_crt_process_attach+0x000000c7
d7d8fb9 opencv_imgproc420d!dllmain_crt_dispatch+0x00000029
d7d93a3 opencv_imgproc420d!dllmain_dispatch+0x00000093
d7d958f opencv_imgproc420d!_DllMainCRTStartup+0x0000001f
776f9280 ntdll!LdrpCallInitRoutine+0x00000014
776ffeb7 ntdll!LdrpRunInitializeRoutines+0x0000026f
7770b474 ntdll!LdrpInitializeProcess+0x00001402
77709f31 ntdll!_LdrpInitialize+0x00000078
776f9799 ntdll!LdrInitializeThunk+0x00000010

0:000> !heap -p -a 0x007E1248
address 007e1248 found in
_HEAP @ 770000
HEAP_ENTRY Size Prev Flags UserPtr UserSize - state
007e1210 000e 0000 [00] 007e1228 00054 - (busy)
7773d929 ntdll!RtlAllocateHeap+0x00000274
f1b4a5 ucrtbased!heap_alloc_dbg_internal+0x00000195
f1b2c6 ucrtbased!heap_alloc_dbg+0x00000036
f1da3a ucrtbased!_malloc_dbg+0x0000001a
f1e354 ucrtbased!malloc+0x00000014
c0af7ed opencv_core420d!operator new+0x0000000d
bfde77f opencv_core420d!cv::getInitializationMutex+0x0000004f
bfed038 opencv_core420d!cv::utils::trace::details::getTraceManager+0x00000048
bfed661 opencv_core420d!cv::utils::trace::details::TraceManager::isActivated+0x00000031
bfe603b opencv_core420d!cv::utils::trace::details::Region::Region+0x0000005b
c01ca80 opencv_core420d!cv::utils::logging::LogTagManager::assign+0x00000050
c0159a2 opencv_core420d!cv::utils::logging::LogTagManager::LogTagManager+0x000000f2
bdee90b opencv_core420d!cv::utils::logging::internal::GlobalLoggingInitStruct::GlobalLoggingInitStruct+0x0000003b
bdeecb5 opencv_core420d!cv::utils::logging::internal::getGlobalLoggingInitStruct+0x00000065
bdee8b3 opencv_core420d!cv::utils::logging::internal::GlobalLoggingInitCall::GlobalLoggingInitCall+0x00000013
bc76f2d opencv_core420d!cv::utils::logging::internal::`dynamic initializer for 'globalLoggingInitCall''+0x0000000d
f359df ucrtbased!_initterm+0x0000003f
c0b17c7 opencv_core420d!dllmain_crt_process_attach+0x000000c7
c0b1689 opencv_core420d!dllmain_crt_dispatch+0x00000029
c0b1a73 opencv_core420d!dllmain_dispatch+0x00000093
c0b1c5f opencv_core420d!_DllMainCRTStartup+0x0000001f
776f9280 ntdll!LdrpCallInitRoutine+0x00000014
776ffeb7 ntdll!LdrpRunInitializeRoutines+0x0000026f
7770b474 ntdll!LdrpInitializeProcess+0x00001402
77709f31 ntdll!_LdrpInitialize+0x00000078
776f9799 ntdll!LdrInitializeThunk+0x00000010

0:000> !heap -p -a 0x007B9DD0
address 007b9dd0 found in
_HEAP @ 770000
HEAP_ENTRY Size Prev Flags UserPtr UserSize - state
007b9d98 0012 0000 [00] 007b9db0 00078 - (busy)
7773d929 ntdll!RtlAllocateHeap+0x00000274
f1b4a5 ucrtbased!heap_alloc_dbg_internal+0x00000195
f1b2c6 ucrtbased!heap_alloc_dbg+0x00000036
f1da3a ucrtbased!_malloc_dbg+0x0000001a
f1e354 ucrtbased!malloc+0x00000014
c0af7ed opencv_core420d!operator new+0x0000000d
bfdf0ba opencv_core420d!cv::details::getTlsStorage+0x0000006a
bfd6570 opencv_core420d!cv::TLSDataContainer::TLSDataContainer+0x00000020
bfe53d5 opencv_core420d!cv::TLSDatacv::utils::trace::details::TraceManagerThreadLocal::TLSDatacv::utils::trace::details::TraceManagerThreadLocal+0x00000035
bfe5465 opencv_core420d!cv::TLSDataAccumulatorcv::utils::trace::details::TraceManagerThreadLocal::TLSDataAccumulatorcv::utils::trace::details::TraceManagerThreadLocal+0x00000035
bfe6eae opencv_core420d!cv::utils::trace::details::TraceManager::TraceManager+0x0000006e
bfed155 opencv_core420d!cv::utils::trace::details::getTraceManagerCallOnce+0x00000065
bfed056 opencv_core420d!cv::utils::trace::details::getTraceManager+0x00000066
bfed661 opencv_core420d!cv::utils::trace::details::TraceManager::isActivated+0x00000031
bfe603b opencv_core420d!cv::utils::trace::details::Region::Region+0x0000005b
c01ca80 opencv_core420d!cv::utils::logging::LogTagManager::assign+0x00000050
c0159a2 opencv_core420d!cv::utils::logging::LogTagManager::LogTagManager+0x000000f2
bdee90b opencv_core420d!cv::utils::logging::internal::GlobalLoggingInitStruct::GlobalLoggingInitStruct+0x0000003b
bdeecb5 opencv_core420d!cv::utils::logging::internal::getGlobalLoggingInitStruct+0x00000065
bdee8b3 opencv_core420d!cv::utils::logging::internal::GlobalLoggingInitCall::GlobalLoggingInitCall+0x00000013
bc76f2d opencv_core420d!cv::utils::logging::internal::`dynamic initializer for 'globalLoggingInitCall''+0x0000000d
f359df ucrtbased!_initterm+0x0000003f
c0b17c7 opencv_core420d!dllmain_crt_process_attach+0x000000c7
c0b1689 opencv_core420d!dllmain_crt_dispatch+0x00000029
c0b1a73 opencv_core420d!dllmain_dispatch+0x00000093
c0b1c5f opencv_core420d!_DllMainCRTStartup+0x0000001f
776f9280 ntdll!LdrpCallInitRoutine+0x00000014
776ffeb7 ntdll!LdrpRunInitializeRoutines+0x0000026f
7770b474 ntdll!LdrpInitializeProcess+0x00001402
77709f31 ntdll!_LdrpInitialize+0x00000078
776f9799 ntdll!LdrInitializeThunk+0x00000010

0:000> !heap -p -a 0x007CAD90
address 007cad90 found in
_HEAP @ 770000
HEAP_ENTRY Size Prev Flags UserPtr UserSize - state
007cad58 000b 0000 [00] 007cad70 0003c - (busy)
7773d929 ntdll!RtlAllocateHeap+0x00000274
f1b4a5 ucrtbased!heap_alloc_dbg_internal+0x00000195
f1b2c6 ucrtbased!heap_alloc_dbg+0x00000036
f1da3a ucrtbased!_malloc_dbg+0x0000001a
f1e354 ucrtbased!malloc+0x00000014
c0acb0c opencv_core420d!__itt_domain_createA_init_3_0+0x0000015c
bfed77e opencv_core420d!cv::utils::trace::details::isITTEnabled+0x000000ee
bfe6fd1 opencv_core420d!cv::utils::trace::details::TraceManager::TraceManager+0x00000191
bfed155 opencv_core420d!cv::utils::trace::details::getTraceManagerCallOnce+0x00000065
bfed056 opencv_core420d!cv::utils::trace::details::getTraceManager+0x00000066
bfed661 opencv_core420d!cv::utils::trace::details::TraceManager::isActivated+0x00000031
bfe603b opencv_core420d!cv::utils::trace::details::Region::Region+0x0000005b
c01ca80 opencv_core420d!cv::utils::logging::LogTagManager::assign+0x00000050
c0159a2 opencv_core420d!cv::utils::logging::LogTagManager::LogTagManager+0x000000f2
bdee90b opencv_core420d!cv::utils::logging::internal::GlobalLoggingInitStruct::GlobalLoggingInitStruct+0x0000003b
bdeecb5 opencv_core420d!cv::utils::logging::internal::getGlobalLoggingInitStruct+0x00000065
bdee8b3 opencv_core420d!cv::utils::logging::internal::GlobalLoggingInitCall::GlobalLoggingInitCall+0x00000013
bc76f2d opencv_core420d!cv::utils::logging::internal::`dynamic initializer for 'globalLoggingInitCall''+0x0000000d
f359df ucrtbased!_initterm+0x0000003f
c0b17c7 opencv_core420d!dllmain_crt_process_attach+0x000000c7
c0b1689 opencv_core420d!dllmain_crt_dispatch+0x00000029
c0b1a73 opencv_core420d!dllmain_dispatch+0x00000093
c0b1c5f opencv_core420d!_DllMainCRTStartup+0x0000001f
776f9280 ntdll!LdrpCallInitRoutine+0x00000014
776ffeb7 ntdll!LdrpRunInitializeRoutines+0x0000026f
7770b474 ntdll!LdrpInitializeProcess+0x00001402
77709f31 ntdll!_LdrpInitialize+0x00000078
776f9799 ntdll!LdrInitializeThunk+0x00000010

@mshabunin
Copy link
Contributor

These are static data structures, they are allocated only once and should not be considered a memory leak. You can suppress these hits, we have suppression file for valgrind: https://github.com/opencv/opencv/blob/master/platforms/scripts/valgrind.supp , but I don't know whether the MSVC have similar mechanism.

I'll close the issue, feel free to reopen if you have additional details.

@libaineu2004
Copy link
Author

These are static data structures, they are allocated only once and should not be considered a memory leak. You can suppress these hits, we have suppression file for valgrind: https://github.com/opencv/opencv/blob/master/platforms/scripts/valgrind.supp , but I don't know whether the MSVC have similar mechanism.

I'll close the issue, feel free to reopen if you have additional details.

  1. I found the reason. Only MFC debug mode will prompt a memory leak. The release mode does not.
  2. In addition, the windows console program will not leak memory.
  3. For the problem of MFC debug, my solution is to delay the loading of the opencv dll file. That is, after the dll file of mfc is loaded, the dll file of opencv is loaded, so no error is reported.
    Click on the VC ++ MFC Debug project properties, enter the property page, find common properties, linker, input, DLL options for lazy loading, and then add the names of all dlls in the OpenCV bin file to the lazy DLL. After adding it, click OK, and then recompile the program, no memory leak occurred.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate incomplete needs reproducer Provide complete minimal reproducer with input data
Projects
None yet
Development

No branches or pull requests

3 participants