title: OpenCV resize memory leak
body: <p>I have a little bigger application that was generating memory leaks. I could nail them down to a <code>cv::resize</code> call. These leaks are not causing guaranteed crashes, but instead it seemed to be system dependent. It crashed on one, but not the other, "only" giving a first chance exception there.</p>
  
  <p>I reduced the code drastically to just this (<strong>this is not crashing</strong>):</p>
  
  <pre><code>#include &lt;opencv2\opencv.hpp&gt;
  
  int main(int argc, char *argv[])
  {
      _CrtMemState s1, s2, s3;
      _CrtMemCheckpoint(&amp;s1);
  
      cv::Mat src = cv::imread("C:\\Users\\Gunnar\\Pictures\\test.jpg");
  
      cv::Size targetSize(600, 800);
  
      cv::Mat dst(targetSize, src.type());
  
      cv::resize(src, dst, targetSize, 0, 0, cv::INTER_CUBIC);
  
      cv::imshow("resize test", dst);
  
      cv::waitKey(0);
  
      _CrtMemCheckpoint(&amp;s2);
  
      if (_CrtMemDifference(&amp;s3, &amp;s1, &amp;s2))
      {
          _CrtMemDumpStatistics(&amp;s3);
          _CrtDumpMemoryLeaks();
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Still I do get memory leaks on this on both systems.</p>
  
  <p>This is using OpenCV 3, Windows 7 as developement system and Windows 10 as the other, both 64 bit. This is compiled for 64 bit.</p>
  
  <p>I'm pretty sure this is not a false positive since it would not crash in my application otherwise, but I can't seem to figure out why this is happening or what I need to do to fix this. Does anybody have an idea what is going on here?</p>
  
  <p>Edit:<br>
  Was about to edit the result of the <code>if</code>, but SO told me <code>Body is limited to 30000 characters; you entered 49686</code>, so here is just the <code>_CrtMemDumpStatistics</code>:</p>
  
  <pre><code>0 bytes in 0 Free Blocks.
  2617124 bytes in 21 Normal Blocks.
  176508 bytes in 154 CRT Blocks.
  0 bytes in 0 Ignore Blocks.
  0 bytes in 0 Client Blocks.
  Largest number used: 2899588 bytes.
  Total allocations: 3113364 bytes.
  </code></pre>
  
  <p>Edit 2:<br>
  I'm working in Visual Studio 2013 (Compile as default). OpenCV 3.0.0.
  /MDd for Debug and /MD for Release.</p>
  
  <p>Debug Linker Command Line:</p>
  
  <pre><code>/OUT:"C:\Users\Gunnar\Documents\Visual Studio 2013\Projects\ResizeTest\x64\Debug\ResizeTest.exe" /MANIFEST /NXCOMPAT /PDB:"C:\Users\Gunnar\Documents\Visual Studio 2013\Projects\ResizeTest\x64\Debug\ResizeTest.pdb" /DYNAMICBASE "opencv_ts300d.lib" "opencv_world300d.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /MACHINE:X64 /INCREMENTAL /PGD:"C:\Users\Gunnar\Documents\Visual Studio 2013\Projects\ResizeTest\x64\Debug\ResizeTest.pgd" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"x64\Debug\ResizeTest.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"E:\OpenCV\build\x64\vc12\lib" /TLBID:1 
  </code></pre>
  
  <p>Release Linker Command Line: </p>
  
  <pre><code>/OUT:"C:\Users\Gunnar\Documents\Visual Studio 2013\Projects\ResizeTest\x64\Release\ResizeTest.exe" /MANIFEST /LTCG /NXCOMPAT /PDB:"C:\Users\Gunnar\Documents\Visual Studio 2013\Projects\ResizeTest\x64\Release\ResizeTest.pdb" /DYNAMICBASE "opencv_ts300.lib" "opencv_world300.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /MACHINE:X64 /OPT:REF /INCREMENTAL:NO /PGD:"C:\Users\Gunnar\Documents\Visual Studio 2013\Projects\ResizeTest\x64\Release\ResizeTest.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"x64\Release\ResizeTest.exe.intermediate.manifest" /OPT:ICF /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"E:\OpenCV\build\x64\vc12\lib" /TLBID:1 
  </code></pre>
  
  <p>Edit 3:<br>
  These are the exception messages I get when debugging my bigger application:</p>
  
  <pre><code>VERIFIER STOP 0000000000000900: pid 0x1204: A heap allocation was leaked. 
  
  000001DF41222800 : Address of the leaked allocation. Run !heap -p -a &lt;address&gt; to get additional information about the allocation.
  000001DF317DFFB0 : Address to the allocation stack trace. Run dps &lt;address&gt; to view the allocation stack.
  000001DF415C1FD8 : Address of the owner dll name. Run du &lt;address&gt; to read the dll name.
  00007FF8AA7D0000 : Base of the owner dll. Run .reload &lt;dll_name&gt; = &lt;address&gt; to reload the owner dll. Use 'lm' to get more information about the loaded and unloaded modules.
  </code></pre>