title: _CrtMemDumpAllObjectsSince suddenly reports 700 allocations after one call to realloc
body: <p>I suspect I have some memory leaks problem so I defined two functions that I can call from the immediate window while stepping through my code:</p>
  
  <pre><code>_CrtMemState s1;
  
  void SetMemCheckPoint() {
      _CrtMemCheckpoint(&amp;s1);
  }
  
  void CompareMemory() {
      _CrtMemDumpAllObjectsSince(&amp;s1);
  }
  </code></pre>
  
  <p>Then I have this line somewhere:</p>
  
  <pre><code>buf = (char*)realloc(buf, (strlen(src)+1)*sizeof(char)); //yes I'm aware sizeof(char) = 1
  //Don't worry, after this, if (!buf) I fast fail and exit(-1)
  </code></pre>
  
  <p>Just before stepping through this line, calling <code>SetMemCheckPoint()</code> then <code>CompareMemory()</code> in the immediate window reports no new allocations (as it obviously should).</p>
  
  <p>Then, just after stepping through this line, calling <code>CompareMemory()</code> in the immediate window reports this:</p>
  
  <pre><code>Dumping objects -&gt;
  {6886} normal block at 0x19941B90, 58 bytes long.
   Data: &lt;C:\Users\XXXXXXX&gt; 43 3A 5C 55 73 65 72 73 5C XX XX XX XX XX XX XX
  {3974} client block at 0x1921D600, subtype 0, 10 bytes long.
   Data: &lt;% /m K    &gt; 25 00 2F 6D 00 4B 00 CD CD CD 
  {3807} client block at 0x05D45800, subtype 0, 16 bytes long.
   Data: &lt;r               &gt; 72 0B CB 00 CD CD CD CD CD CD CD CD CD CD CD CD 
  </code></pre>
  
  <p>[... 700 more allocations ...]</p>
  
  <pre><code>{153} client block at 0x05D5BF90, subtype 0, 11 bytes long.
   Data: &lt;log.log    &gt; 6C 6F 67 2E 6C 6F 67 00 CD CD CD 
  {152} client block at 0x05BD5C00, subtype 0, 48 bytes long.
   Data: &lt;                &gt; 90 BF D5 05 08 00 00 00 0B 00 00 00 CD CD CD CD 
  {151} client block at 0x05C5B210, subtype 0, 32 bytes long.
   Data: &lt;                &gt; 00 00 00 00 00 00 00 00 E8 03 00 00 00 00 00 00 
  Object dump complete.
  </code></pre>
  
  <p>All these allocations seems to be memory allocated <em>before</em> calling <code>SetMemCheckPoint()</code>.</p>
  
  <p>Is MS crt <code>realloc()</code> somehow messing with the (MS) crt debug heap and corrupting my checkpoint s1?</p>
  
  <p>Or am I missing something ?</p>
  
  <h2>edit</h2>
  
  <p>This code is in a dll called from Excel macros (vba). Maybe there are some strange interactions between Excel and my debug-compiled dll (that is itself dynamically linked to msvcr120d.dll).</p>
  
  <p>Also, the realloc call does return a new pointer, but subsequent calls seem to "cycle" between a few addresses. I am wondering if this causes <code>_CrtMemDumpAllObjectsSince</code> to see this "new" pointer as an "old" allocation, and then dump all allocations since this "old" one ?</p>
  
  <p>I can't reproduce it in a minimal program :( It seems it has something to do with interactions between my dll and Excel/3rd party code indeed...</p>