memory leaks

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
mcunha
Posts: 6
Joined: 2017-10-13T10:35:01-07:00
Authentication code: 1151

memory leaks

Post by mcunha »

Hello,

I'm having memory leaks issues with ImageMagick-7.0.7-5.
Any call to any ImageMagick methods will generate memory leaks.

For example:
If I create a Visual Studio 2013 C++ project on Win7, dialog based with MFC in a shared DLL, Multi-threaded Debug DLL (/MDd)
calling Magick::InitializeMagick(""); in the OnInitDialog() of my main dialog and
Magick::TerminateMagick(); in the ::OnClose() method.

when I quit the application I got the following memory leaks:

Code: Select all

Detected memory leaks!
Dumping objects ->
..\..\ImageMagick\MagickCore\semaphore.c(157) : {929} normal block at 0x006B16B8, 135 bytes long.
 Data: <  k     ` k     > B8 16 6B 00 ED ED ED ED 60 17 6B 00 00 00 00 00 
..\..\ImageMagick\MagickCore\semaphore.c(157) : {928} normal block at 0x006B1580, 135 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD 
..\..\ImageMagick\MagickCore\semaphore.c(157) : {927} normal block at 0x006B1448, 135 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD 
..\..\ImageMagick\MagickCore\semaphore.c(157) : {926} normal block at 0x006B12D8, 135 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD 
..\..\ImageMagick\MagickCore\semaphore.c(157) : {925} normal block at 0x006B11A0, 135 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD 
..\..\ImageMagick\MagickCore\semaphore.c(157) : {924} normal block at 0x006B10A0, 135 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD 
..\..\ImageMagick\MagickCore\semaphore.c(157) : {923} normal block at 0x006B07F8, 135 bytes long.
 Data: <  k     H k     > F8 07 6B 00 ED ED ED ED 48 10 6B 00 00 00 00 00 
..\..\ImageMagick\MagickCore\memory.c(171) : {922} normal block at 0x006B07A8, 16 bytes long.
 Data: <  k @ k         > 08 0E 6B 00 40 07 6B 00 00 00 00 00 00 00 00 00 
..\..\ImageMagick\MagickCore\memory.c(171) : {921} normal block at 0x006B0E08, 13 bytes long.
 Data: <[boot-strap] > 5B 62 6F 6F 74 2D 73 74 72 61 70 5D 00 
..\..\ImageMagick\MagickCore\memory.c(171) : {920} normal block at 0x006B0740, 40 bytes long.
 Data: <      k         > 00 00 00 00 08 0E 6B 00 00 00 00 00 00 00 00 00 
..\..\ImageMagick\MagickCore\semaphore.c(157) : {919} normal block at 0x006B0F68, 135 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD 
..\..\ImageMagick\MagickCore\memory.c(171) : {914} normal block at 0x006B0C88, 44 bytes long.
 Data: <  k  Z      p   > A8 07 6B 00 D0 5A 96 0F 00 00 00 00 70 BF 8D 0F 
..\..\ImageMagick\MagickCore\semaphore.c(157) : {913} normal block at 0x006B0EA0, 135 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD 
..\..\ImageMagick\MagickCore\semaphore.c(157) : {912} normal block at 0x006B0BC0, 135 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD 
..\..\ImageMagick\MagickCore\semaphore.c(157) : {911} normal block at 0x006B0920, 135 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD 
..\..\ImageMagick\MagickCore\memory.c(171) : {838} normal block at 0x006B0B78, 8 bytes long.
 Data: <h k     > 68 0D 6B 00 00 00 00 00 
..\..\ImageMagick\MagickCore\memory.c(171) : {837} normal block at 0x006B0D68, 44 bytes long.
 Data: < :              > F8 3A 9A 0F 00 00 00 00 00 00 00 00 00 00 00 00 
..\..\ImageMagick\MagickCore\semaphore.c(157) : {765} normal block at 0x006B0A40, 135 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD 
..\..\ImageMagick\MagickCore\memory.c(171) : {764} normal block at 0x006B09E8, 28 bytes long.
 Data: <        x k x k > FF FF FF FF 01 00 00 00 78 0B 6B 00 78 0B 6B 00 
..\..\ImageMagick\MagickCore\semaphore.c(157) : {755} normal block at 0x006B0678, 135 bytes long.
 Data: <x k     0 j     > 78 06 6B 00 ED ED ED ED 30 F5 6A 00 00 00 00 00 
..\..\ImageMagick\MagickCore\semaphore.c(157) : {754} normal block at 0x006AE9B8, 135 bytes long.
 Data: <  j     P j     > B8 E9 6A 00 ED ED ED ED 50 FE 6A 00 00 00 00 00 
..\..\ImageMagick\MagickCore\semaphore.c(157) : {753} normal block at 0x006AE8F0, 135 bytes long.
 Data: <          j     > CD CD CD CD CD CD CD CD F0 E8 6A 00 ED ED ED ED 
..\..\ImageMagick\MagickCore\semaphore.c(157) : {752} normal block at 0x006AEDA8, 135 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD 
..\..\ImageMagick\MagickCore\semaphore.c(157) : {735} normal block at 0x006AEAE0, 135 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD 
..\..\ImageMagick\MagickCore\semaphore.c(157) : {734} normal block at 0x006AEF38, 135 bytes long.
 Data: <8 j     X j     > 38 EF 6A 00 ED ED ED ED 58 F1 6A 00 00 00 00 00 
..\..\ImageMagick\MagickCore\memory.c(171) : {733} normal block at 0x006B05F0, 8 bytes long.
 Data: <  j     > C8 F0 6A 00 00 00 00 00 
..\..\ImageMagick\MagickCore\memory.c(171) : {732} normal block at 0x006B0588, 41 bytes long.
 Data: <%t %r %u %v %d %> 25 74 20 25 72 20 25 75 20 25 76 20 25 64 20 25 
..\..\ImageMagick\MagickCore\memory.c(171) : {731} normal block at 0x006B0538, 14 bytes long.
 Data: <Magick-%g.log > 4D 61 67 69 63 6B 2D 25 67 2E 6C 6F 67 00 
..\..\ImageMagick\MagickCore\memory.c(171) : {730} normal block at 0x006AF5B0, 11 bytes long.
 Data: <[built-in] > 5B 62 75 69 6C 74 2D 69 6E 5D 00 
..\..\ImageMagick\MagickCore\memory.c(171) : {729} normal block at 0x006AF0C8, 112 bytes long.
 Data: <          j     > 00 00 00 00 01 00 00 00 B0 F5 6A 00 00 00 00 00 
..\..\ImageMagick\MagickCore\memory.c(171) : {725} normal block at 0x006B04E8, 16 bytes long.
 Data: <  k X k         > F0 03 6B 00 58 03 6B 00 00 00 00 00 00 00 00 00 
..\..\ImageMagick\MagickCore\memory.c(171) : {724} normal block at 0x006B0438, 1 bytes long.
 Data: < > 00 
..\..\ImageMagick\MagickCore\memory.c(171) : {723} normal block at 0x006B03F0, 12 bytes long.
 Data: <Exception// > 45 78 63 65 70 74 69 6F 6E 2F 2F 00 
..\..\ImageMagick\MagickCore\memory.c(171) : {722} normal block at 0x006B03A8, 9 bytes long.
 Data: <built-in > 62 75 69 6C 74 2D 69 6E 00 
..\..\ImageMagick\MagickCore\memory.c(171) : {721} normal block at 0x006B0358, 20 bytes long.
 Data: <  k   k 8 k     > A8 03 6B 00 F0 03 6B 00 38 04 6B 00 00 00 00 00 
..\..\ImageMagick\MagickCore\semaphore.c(157) : {687} normal block at 0x006B0290, 135 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD 
..\..\ImageMagick\MagickCore\memory.c(171) : {686} normal block at 0x006A1148, 44 bytes long.
 Data: <  k  Z      @   > E8 04 6B 00 D0 5A 96 0F 00 00 00 00 40 E4 8C 0F 
..\..\ImageMagick\MagickCore\semaphore.c(157) : {682} normal block at 0x006B00D0, 135 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD 
..\..\ImageMagick\MagickCore\semaphore.c(157) : {657} normal block at 0x006AEC70, 135 bytes long.
 Data: <        p j     > CD CD CD CD CD CD CD CD 70 EC 6A 00 ED ED ED ED 
..\..\ImageMagick\MagickCore\memory.c(171) : {656} normal block at 0x006AEC18, 28 bytes long.
 Data: <          k   k > FF FF FF FF 01 00 00 00 F0 05 6B 00 F0 05 6B 00 
..\..\ImageMagick\MagickCore\semaphore.c(157) : {651} normal block at 0x006AE7B8, 135 bytes long.
 Data: <  j     ` j     > B8 E7 6A 00 ED ED ED ED 60 E8 6A 00 00 00 00 00 
{351} normal block at 0x0069CE40, 32 bytes long.
 Data: <                > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
{350} normal block at 0x0069CDE0, 32 bytes long.
 Data: <                > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
{349} normal block at 0x0069CDA0, 4 bytes long.
 Data: <    > 00 00 00 00 
{348} normal block at 0x0069CD40, 32 bytes long.
 Data: <                > 00 00 00 00 00 00 00 00 CD CD CD CD CD CD CD CD 
{347} normal block at 0x0069CCE0, 32 bytes long.
 Data: <                > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
{346} normal block at 0x006974A0, 32 bytes long.
 Data: <                > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
{345} normal block at 0x0069C4A0, 2048 bytes long.
 Data: <                > AA 00 00 00 00 00 00 00 0C 00 00 00 0C 00 00 00 
{339} normal block at 0x0069C430, 48 bytes long.
 Data: <  i (           > 88 92 69 00 28 00 00 00 00 00 00 00 00 00 00 00 
{338} normal block at 0x0069C3E8, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{337} normal block at 0x0069C3A0, 8 bytes long.
 Data: <      i > 01 00 00 00 E8 C3 69 00 
{335} normal block at 0x0069C330, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 0E 00 
{334} normal block at 0x0069C2E0, 20 bytes long.
 Data: <T   p   p       > 54 00 00 00 70 B0 AD 00 70 B1 AD 00 D0 B1 AD 00 
{333} normal block at 0x0069C270, 48 bytes long.
 Data: <  i (           > 88 92 69 00 28 00 00 00 00 00 00 00 00 00 00 00 
{332} normal block at 0x0069BD18, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{331} normal block at 0x0069BCD0, 8 bytes long.
 Data: <      i > 01 00 00 00 18 BD 69 00 
{336} normal block at 0x0069C1D8, 92 bytes long.
 Data: <` i ` i h i ( i > 60 95 69 00 60 97 69 00 68 99 69 00 28 9B 69 00 
{329} normal block at 0x0069C168, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 0E 00 
{328} normal block at 0x0069C118, 20 bytes long.
 Data: <  i         @   > D8 BF 69 00 00 00 00 00 F0 8D AD 00 40 8E AD 00 
{327} normal block at 0x0069C0D8, 4 bytes long.
 Data: <  i > 0C 8B 69 00 
{326} normal block at 0x0069C090, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{325} normal block at 0x0069C048, 8 bytes long.
 Data: <      i > 01 00 00 00 90 C0 69 00 
{324} normal block at 0x0069B7E8, 4 bytes long.
 Data: <  i > D8 BF 69 00 
{323} normal block at 0x0069BFD8, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 08 00 
{322} normal block at 0x0069BF68, 48 bytes long.
 Data: <  i (           > 88 92 69 00 28 00 00 00 00 00 00 00 00 00 00 00 
{321} normal block at 0x0069BF20, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{320} normal block at 0x0069BED8, 8 bytes long.
 Data: <      i > 01 00 00 00 20 BF 69 00 
{318} normal block at 0x0069BE68, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 0E 00 
{317} normal block at 0x0069BE18, 20 bytes long.
 Data: <                > 04 00 00 00 10 98 AD 00 D0 98 AD 00 20 99 AD 00 
{316} normal block at 0x0069BDA8, 48 bytes long.
 Data: <  i (           > 88 92 69 00 28 00 00 00 00 00 00 00 00 00 00 00 
{315} normal block at 0x0069BD60, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{314} normal block at 0x0069B7A0, 8 bytes long.
 Data: <    ` i > 01 00 00 00 60 BD 69 00 
{312} normal block at 0x0069BC60, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 0E 00 
{311} normal block at 0x0069BC10, 20 bytes long.
 Data: <P               > 50 00 00 00 00 00 00 00 B0 96 AD 00 D0 96 AD 00 
{310} normal block at 0x0069BBA0, 48 bytes long.
 Data: <  i (           > 88 92 69 00 28 00 00 00 00 00 00 00 00 00 00 00 
{309} normal block at 0x0069BB58, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{308} normal block at 0x0069BB10, 8 bytes long.
 Data: <    X i > 01 00 00 00 58 BB 69 00 
{306} normal block at 0x0069BAA0, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 0E 00 
{305} normal block at 0x0069BA50, 20 bytes long.
 Data: <  i `   `       > E0 B8 69 00 60 AB AD 00 60 AC AD 00 10 AD AD 00 
{304} normal block at 0x0069B9E0, 48 bytes long.
 Data: <  i          )  > EC B9 69 00 80 E8 AE 00 80 E9 AE 00 20 29 AC 00 
{303} normal block at 0x0069B998, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{302} normal block at 0x0069B950, 8 bytes long.
 Data: <      i > 01 00 00 00 98 B9 69 00 
{301} normal block at 0x006995D0, 4 bytes long.
 Data: <  i > E0 B8 69 00 
{300} normal block at 0x0069B8E0, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 08 00 
{299} normal block at 0x0069B870, 48 bytes long.
 Data: <  i (           > 88 92 69 00 28 00 00 00 00 00 00 00 00 00 00 00 
{298} normal block at 0x0069B828, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{297} normal block at 0x00697FB0, 8 bytes long.
 Data: <    ( i > 01 00 00 00 28 B8 69 00 
{295} normal block at 0x0069B730, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 0E 00 
{294} normal block at 0x0069B6E0, 20 bytes long.
 Data: <D               > 44 00 00 00 00 00 00 00 B0 9A AD 00 D0 9A AD 00 
{293} normal block at 0x0069B670, 48 bytes long.
 Data: <  i (           > 88 92 69 00 28 00 00 00 00 00 00 00 00 00 00 00 
{292} normal block at 0x0069B628, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{291} normal block at 0x0069B5E0, 8 bytes long.
 Data: <    ( i > 01 00 00 00 28 B6 69 00 
{289} normal block at 0x0069B570, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 0E 00 
{288} normal block at 0x0069B520, 20 bytes long.
 Data: <H               > 48 00 00 00 00 00 00 00 A0 81 AD 00 C0 81 AD 00 
{287} normal block at 0x0069B4B0, 48 bytes long.
 Data: <  i (           > 88 92 69 00 28 00 00 00 00 00 00 00 00 00 00 00 
{286} normal block at 0x0069B468, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{285} normal block at 0x0069B420, 8 bytes long.
 Data: <    h i > 01 00 00 00 68 B4 69 00 
{283} normal block at 0x0069B3B0, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 0E 00 
{282} normal block at 0x0069B360, 20 bytes long.
 Data: <L               > 4C 00 00 00 00 00 00 00 E0 99 AD 00 00 9A AD 00 
{281} normal block at 0x0069B2F0, 48 bytes long.
 Data: <  i (           > 88 92 69 00 28 00 00 00 00 00 00 00 00 00 00 00 
{280} normal block at 0x0069B2A8, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{279} normal block at 0x0069B260, 8 bytes long.
 Data: <      i > 01 00 00 00 A8 B2 69 00 
{277} normal block at 0x0069B1F0, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 0E 00 
{276} normal block at 0x0069B1A0, 20 bytes long.
 Data: <@   p           > 40 00 00 00 70 9B AD 00 C0 9C AD 00 10 9D AD 00 
{275} normal block at 0x0069B130, 48 bytes long.
 Data: <  i (           > 88 92 69 00 28 00 00 00 00 00 00 00 00 00 00 00 
{274} normal block at 0x0069B0E8, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{273} normal block at 0x0069B0A0, 8 bytes long.
 Data: <      i > 01 00 00 00 E8 B0 69 00 
{271} normal block at 0x0069B030, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 0E 00 
{270} normal block at 0x0069AFE0, 20 bytes long.
 Data: <<       p       > 3C 00 00 00 00 00 00 00 70 84 AD 00 B0 84 AD 00 
{269} normal block at 0x0069AF70, 48 bytes long.
 Data: <  i (           > 88 92 69 00 28 00 00 00 00 00 00 00 00 00 00 00 
{268} normal block at 0x0069AF28, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{267} normal block at 0x0069AEE0, 8 bytes long.
 Data: <    ( i > 01 00 00 00 28 AF 69 00 
{265} normal block at 0x0069AE70, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 0E 00 
{264} normal block at 0x0069AE20, 20 bytes long.
 Data: <8               > 38 00 00 00 00 00 00 00 80 8B AD 00 C0 8B AD 00 
{263} normal block at 0x0069ADB0, 48 bytes long.
 Data: <  i (           > 88 92 69 00 28 00 00 00 00 00 00 00 00 00 00 00 
{262} normal block at 0x0069AD68, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{261} normal block at 0x0069AD20, 8 bytes long.
 Data: <    h i > 01 00 00 00 68 AD 69 00 
{259} normal block at 0x0069ACB0, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 0E 00 
{258} normal block at 0x0069AC60, 20 bytes long.
 Data: <4           0   > 34 00 00 00 F0 88 AD 00 F0 89 AD 00 30 8A AD 00 
{257} normal block at 0x0069ABF0, 48 bytes long.
 Data: <  i (           > 88 92 69 00 28 00 00 00 00 00 00 00 00 00 00 00 
{256} normal block at 0x0069ABA8, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{255} normal block at 0x0069AB60, 8 bytes long.
 Data: <      i > 01 00 00 00 A8 AB 69 00 
{253} normal block at 0x0069AAF0, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 0E 00 
{252} normal block at 0x0069AAA0, 20 bytes long.
 Data: <0               > 30 00 00 00 E0 86 AD 00 E0 87 AD 00 20 88 AD 00 
{251} normal block at 0x0069AA30, 48 bytes long.
 Data: <  i (           > 88 92 69 00 28 00 00 00 00 00 00 00 00 00 00 00 
{250} normal block at 0x0069A9E8, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{249} normal block at 0x0069A450, 8 bytes long.
 Data: <      i > 01 00 00 00 E8 A9 69 00 
{247} normal block at 0x00697F40, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 0E 00 
{246} normal block at 0x00697EF0, 20 bytes long.
 Data: <        @       > 1C 00 00 00 00 00 00 00 40 AA AD 00 80 AA AD 00 
{245} normal block at 0x00697E80, 48 bytes long.
 Data: <  i (           > 88 92 69 00 28 00 00 00 00 00 00 00 00 00 00 00 
{244} normal block at 0x00697E38, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{243} normal block at 0x00697DF0, 8 bytes long.
 Data: <    8~i > 01 00 00 00 38 7E 69 00 
{242} normal block at 0x0069A8A8, 256 bytes long.
 Data: <              + > A7 E6 B0 17 00 00 00 00 00 00 00 00 81 85 2B 0D 
{241} normal block at 0x0069A768, 256 bytes long.
 Data: <  i         0   > B8 A5 69 00 00 00 00 00 00 00 00 00 30 00 00 00 
{240} normal block at 0x0069A628, 256 bytes long.
 Data: <                > EC E4 B7 00 00 00 00 00 00 00 00 00 0C BE B7 00 
{238} normal block at 0x0069A5B8, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 0E 00 
{237} normal block at 0x0069A568, 20 bytes long.
 Data: <,       0       > 2C 00 00 00 00 00 00 00 30 A3 AD 00 80 A3 AD 00 
{236} normal block at 0x0069A4F8, 48 bytes long.
 Data: <  i (           > 88 92 69 00 28 00 00 00 00 00 00 00 00 00 00 00 
{235} normal block at 0x0069A4B0, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{234} normal block at 0x006978C8, 8 bytes long.
 Data: <      i > 01 00 00 00 B0 A4 69 00 
{232} normal block at 0x0069A3E0, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 0E 00 
{231} normal block at 0x0069A390, 20 bytes long.
 Data: <(           0   > 28 00 00 00 00 00 00 00 E0 8F AD 00 30 90 AD 00 
{230} normal block at 0x0069A320, 48 bytes long.
 Data: <  i (           > 88 92 69 00 28 00 00 00 00 00 00 00 00 00 00 00 
{229} normal block at 0x0069A2D8, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{228} normal block at 0x0069A290, 8 bytes long.
 Data: <      i > 01 00 00 00 D8 A2 69 00 
{226} normal block at 0x0069A220, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 0E 00 
{225} normal block at 0x006979D8, 20 bytes long.
 Data: <$       P       > 24 00 00 00 00 00 00 00 50 A8 AD 00 90 A8 AD 00 
{224} normal block at 0x00697968, 48 bytes long.
 Data: <  i (           > 88 92 69 00 28 00 00 00 00 00 00 00 00 00 00 00 
{223} normal block at 0x00697920, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{222} normal block at 0x00699B98, 8 bytes long.
 Data: <     yi > 01 00 00 00 20 79 69 00 
{220} normal block at 0x00697858, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 0E 00 
{219} normal block at 0x00697808, 20 bytes long.
 Data: <            @   > 20 00 00 00 00 00 00 00 00 95 AD 00 40 95 AD 00 
{218} normal block at 0x0069A0E0, 256 bytes long.
 Data: <      h1      + > A7 E6 B0 17 E8 E7 68 31 00 00 00 00 81 85 2B 0D 
{217} normal block at 0x00699FA0, 256 bytes long.
 Data: <"   ,           > 22 00 00 00 2C 00 00 00 00 00 00 00 15 00 00 00 
{216} normal block at 0x00699E60, 256 bytes long.
 Data: <                > EC E4 B7 00 D0 B2 B7 00 00 00 00 00 0C BE B7 00 
{215} normal block at 0x00699DF0, 48 bytes long.
 Data: <  i (           > 88 92 69 00 28 00 00 00 00 00 00 00 00 00 00 00 
{214} normal block at 0x00699DA8, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{213} normal block at 0x00699D60, 8 bytes long.
 Data: <      i > 01 00 00 00 A8 9D 69 00 
{211} normal block at 0x00699CF0, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 0E 00 
{210} normal block at 0x00699CA0, 20 bytes long.
 Data: <        P       > 1C 00 00 00 00 00 00 00 50 A6 AD 00 90 A6 AD 00 
{209} normal block at 0x00699C30, 48 bytes long.
 Data: <  i (           > 88 92 69 00 28 00 00 00 00 00 00 00 00 00 00 00 
{208} normal block at 0x00699BE8, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{207} normal block at 0x006997D0, 8 bytes long.
 Data: <      i > 01 00 00 00 E8 9B 69 00 
{205} normal block at 0x00699B28, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 0E 00 
{204} normal block at 0x00699AD8, 20 bytes long.
 Data: <            @   > 18 00 00 00 00 00 00 00 00 93 AD 00 40 93 AD 00 
{203} normal block at 0x00699A68, 48 bytes long.
 Data: <  i (           > 88 92 69 00 28 00 00 00 00 00 00 00 00 00 00 00 
{202} normal block at 0x00699A20, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{201} normal block at 0x006999D8, 8 bytes long.
 Data: <      i > 01 00 00 00 20 9A 69 00 
{199} normal block at 0x00699968, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 0E 00 
{198} normal block at 0x00699918, 20 bytes long.
 Data: <                > 14 00 00 00 00 00 00 00 C0 80 AD 00 00 81 AD 00 
{197} normal block at 0x006998A8, 48 bytes long.
 Data: <  i (           > 88 92 69 00 28 00 00 00 00 00 00 00 00 00 00 00 
{196} normal block at 0x00699860, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{195} normal block at 0x00699818, 8 bytes long.
 Data: <    ` i > 01 00 00 00 60 98 69 00 
{193} normal block at 0x00699760, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 0E 00 
{192} normal block at 0x00699710, 20 bytes long.
 Data: <                > 10 00 00 00 00 00 00 00 80 A1 AD 00 C0 A1 AD 00 
{191} normal block at 0x006996A0, 48 bytes long.
 Data: <  i (           > 88 92 69 00 28 00 00 00 00 00 00 00 00 00 00 00 
{190} normal block at 0x00699658, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{189} normal block at 0x00699610, 8 bytes long.
 Data: <    X i > 01 00 00 00 58 96 69 00 
{187} normal block at 0x00699560, 52 bytes long.
 Data: <                > 01 00 00 00 00 00 00 00 00 00 00 00 01 00 0E 00 
{186} normal block at 0x00699510, 20 bytes long.
 Data: <                > 0C 00 00 00 00 00 00 00 B0 82 AD 00 F0 82 AD 00 
{185} normal block at 0x00699478, 92 bytes long.
 Data: <` i ` i h i ( i > 60 95 69 00 60 97 69 00 68 99 69 00 28 9B 69 00 
{184} normal block at 0x006993E8, 84 bytes long.
 Data: <  i D           > 18 94 69 00 44 00 00 00 00 00 00 00 80 CB AC 00 
{183} normal block at 0x006993A0, 8 bytes long.
 Data: <        > 01 00 00 00 00 00 00 00 
{182} normal block at 0x00699358, 8 bytes long.
 Data: <      i > 01 00 00 00 A0 93 69 00
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: memory leaks

Post by magick »

We develop ImageMagick under Linux and run a memory debugger against it before a release. No memory leaks are detected. Dirk has more experience with WIndows, perhaps he will comment about your detected leaks under Windows.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: memory leaks

Post by dlemstra »

Some of the memory leaks are expected. This is because of the glib library, it is allocating some memory but I have no idea how we could clean that up. Those are the leaks that don't report a file name. The other ones are from your program. We have tested if we could reproduce the issue with the IMDisplay program (after we added the call to terminate... whoops...) and we cannot reproduce your issue. We started the application, opened an image and closed the application. We only get the expected leaks then. Are you cleaning up your own stuff?
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
mcunha
Posts: 6
Joined: 2017-10-13T10:35:01-07:00
Authentication code: 1151

Re: memory leaks

Post by mcunha »

Code: Select all

// TestImageMagickDlg.cpp : implementation file
//

#include "stdafx.h"
#include "TestImageMagick.h"
#include "TestImageMagickDlg.h"
#include "afxdialogex.h"
#include <Magick++.h>

#ifdef _DEBUG
#ifndef DBG_NEW
#define DBG_NEW new ( __FILE__ , __LINE__ )
#define new DBG_NEW
#endif
#endif  // _DEBUG


// CAboutDlg dialog used for App About

class CAboutDlg : public CDialogEx
{
public:
	CAboutDlg();

// Dialog Data
	enum { IDD = IDD_ABOUTBOX };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

// Implementation
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()


// CTestImageMagickDlg dialog



CTestImageMagickDlg::CTestImageMagickDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(CTestImageMagickDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTestImageMagickDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CTestImageMagickDlg, CDialogEx)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_CLOSE()
END_MESSAGE_MAP()


// CTestImageMagickDlg message handlers

BOOL CTestImageMagickDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		BOOL bNameValid;
		CString strAboutMenu;
		bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
		ASSERT(bNameValid);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// TODO: Add extra initialization here
	Magick::InitializeMagick("");

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CTestImageMagickDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialogEx::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CTestImageMagickDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialogEx::OnPaint();
	}
}

// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CTestImageMagickDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}



void CTestImageMagickDlg::OnClose()
{
	Magick::TerminateMagick();

	CDialogEx::OnClose();
}
mcunha
Posts: 6
Joined: 2017-10-13T10:35:01-07:00
Authentication code: 1151

Re: memory leaks

Post by mcunha »

About my previous reply:
1 - calling Magick::InitializeMagick(""); in the OnInitDialog() of my main dialog
2 - Magick::TerminateMagick(); in the ::OnClose() method.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: memory leaks

Post by dlemstra »

Have you attached a debugger to check if all the methods are being called? Could you share a small demo project that demonstrates the issue?
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
mcunha
Posts: 6
Joined: 2017-10-13T10:35:01-07:00
Authentication code: 1151

Re: memory leaks

Post by mcunha »

Where can I upload the demo?
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: memory leaks

Post by dlemstra »

Use something like dropbox or onedrive.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
mcunha
Posts: 6
Joined: 2017-10-13T10:35:01-07:00
Authentication code: 1151

Re: memory leaks

Post by mcunha »

How about you create a shared folder in something like dropbox or onedrive and then share the link with me.
I will then zip the test project and upload it to your shared folder.
mcunha
Posts: 6
Joined: 2017-10-13T10:35:01-07:00
Authentication code: 1151

Re: memory leaks

Post by mcunha »

Hello?!?!
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: memory leaks

Post by dlemstra »

If you don't have enough space on dropbox or onedrive you could also host your project inside a repository on github.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
ShapeTransformGuy
Posts: 1
Joined: 2019-01-01T09:48:51-07:00
Authentication code: 1152

Re: memory leaks

Post by ShapeTransformGuy »

Nota Bene: the following method works with GraphicMagick. It does not work with ImageMagick.

Another IM member has explained this problem nicely: https://www.imagemagick.org/discourse-s ... hp?t=12434. I copy that explanation here:
OK... I did some more digging today. It turns out that the Memory Check/Dump gets called when MFC exits. Since the IM DLLs haven't unloaded already, it thinks there is a memory leak.

This is pure and simple a bug in the MFC libraries.
The work-around, as noted by others, is to build the libraries with a link to MFC. You don't have to rebuild them all, though; just linking MFC to one is enough; I used CORE_Magick++. You don't have to add any executable code to CORE_Magick++; everything is taken care of by a single #include statement.

Here is one way to accomplish this in practice:

Executive Summary
  • Add #include "stdafx.h" to (any) one of the source code files within CORE_Magick++
  • Tell MSVS/MSVC where to find the stdafx.h file you just added
  • Tell MSVS/MSVC where to find the MFC files referenced in stdafx.h
  • Add the string _AFXDLL to the Preprocessor Directives for the CORE_Magick++ project
  • Rebuild CORE_Magick++, using whatever configuration(s) you need for your project
  • After you've rebuilt CORE_Magick++, rebuild your own project
More Detailed Explanation

Assuming you're using MSVS/MSVC, you have to open one of the files within project CORE_Magick++, and somewhere the file add:

#include "stdafx.h"

You can add this include to any of the source files within CORE_Magick++; I happened to choose Blob.cpp.

Then rebuild CORE_Magick++, which produces files CORE_xx_Magick++_.lib and CORE_xx_Magick++_.dll, where "xx" is either DB or RL depending on whether you've done a debug or release build. Of course, if you're doing a static library build, the dll won't be produced.

When you add the #include stdafx.h statement, MSVS is going to object that it can't find stdafx.h. That's no problem though, because there are several stdafx.h files already present within the ImageMagick source code; I used the one in ..\VisualMagick\configure. You have to add the path to that stdafx.h file to the Additional Include Directories project properties page (under Configuration Properties | C/C++ | General).

Then you have to add MFC paths to the Additional Include Directories project properties for the CORE_Magick++ project; I used these two, which may have been overkill:
  • C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include
  • C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\atlmfc\include
Note that the path to the left of the final "include" may be different in your case; it will depend on your installed version of MSVS, your file configuration, etc. You can find it by looking under Configuration Properties | VC++ Directories | General. Click at the end of the edit box for Include Directories, select <Edit...>, and look at the paths in the Evaluated Value read-only edit box. I know, very obscure. Took me a long time to find that, much flailing about, much pulling out of my hair, etc.

Note:

You can make your IM Build solution for CORE_Magick++ more robust and immune to future changes that will result from upgrading your MSVS version if you make use of one of the helpful (but obscure) "macros" provided by MSVS. There is one called $(VCToolsInstallDir) that will handle this. If you use it, you can simplify the MFC paths; they will look like this:
  • $(VCToolsInstallDir)include
  • $(VCToolsInstallDir)atlmfc\include
The version number string, and everything to the left of it, is included in the macro. I don't know if this macro is present in older versions of MSVS.

Now back to our story...

The last step in the Project Properties world is to add the string _AFXDLL to the "Preprocessor Directives" for CORE_Magick++.

That's it. You don't have to touch any of the other projects within the ImageMagick solution.

Rebuild CORE_Magick++, and then rebuild your project, and you should find that your semaphore-related memory leaks are fixed. Of course, if you've introduced memory leaks of your own, they'll still be there, but at least they won't be lost among vast numbers of falsely-reported ersatz memory leaks.

This explanation assumes that the reader is somewhat familiar with MSVS/MSVC project properties and how to navigate around them. It also assumes that the reader has figured out how to build ImageMagick from the source code using MSVS/MSVC, and knows how to do the correct build for his/her configuration (debug or release, 32-bit or 64-bit, etc.).

Once you dive beneath the surface of MSVS/MSVC and MFC, you are in the world of Microsoft's programmers. They use MFC themselves, and different team members are responsible for different parts of MSVS; for this reason, there are many little inconsistencies, idiosyncrasies, quirks and gotchas that are part of the user experience at this level. It is unfortunate, but unavoidable, I'm sorry to say. A fair amount of frustration and anguish is part of this process, or at least was for me. One just has to bumble through it, at least if one is as slow-witted as I. Perhaps this process can be made less painful by taking a course in MSVS/MSVC, but doing that entails other pain. I've been using Visual Studio and MSVC for about 25 years (since pre-Windows Visual C 6.0, distributed on a whole stack of 3.5" floppy disks) and I still don't think I even know 20% of it.
Post Reply