title: Am I accessing already freed memory, or is DrMemory reporting incorrectly in this case?
body: <p>I have the following program:</p>
  
  <pre><code>#include &lt;vector&gt;
  
  struct Comp1
  {
      float x;
      std::vector&lt;int&gt; vec;
  };
  
  int main()
  {
      std::vector&lt;char&gt; data;
  
      data.resize(sizeof(Comp1));
  
      Comp1* ptr1 = new (&amp;data[0]) Comp1({.3f,{3,4,2,1}});
  
      data.resize(sizeof(Comp1)*2);
  
      Comp1* ptr2 = new (&amp;data[sizeof(Comp1)]) Comp1({.2f,{2,3,4}});
  
      ptr1-&gt;~Comp1();
  
      std::vector&lt;char&gt;::iterator itrStart = data.begin();
      std::vector&lt;char&gt;::iterator itrEnd = itrStart + sizeof(Comp1);
      data.erase(itrStart,itrEnd);
  
      ptr2 = reinterpret_cast&lt;Comp1*&gt;(&amp;data[0]);
  
      ptr2-&gt;~Comp1();
  
      return 0;
  }
  </code></pre>
  
  <p>Compiles with no issue. Executes on my machine with no issue. Run it through GDB and there's nothing reported. My understanding is that everything I've done in the above is correct (except maybe I'm missing the use of <code>std::launder</code> when I <code>reinterpret_cast</code> from a <code>char*</code> to a <code>Comp1*</code>?).</p>
  
  <p>However, invoking DrMemory on this program with:</p>
  
  <pre><code>drmemory.exe test.exe -callstack_max_frames 40 -malloc_max_frames 40 -free_max_frames 40
  </code></pre>
  
  <p>Gives me the following error output:</p>
  
  <pre><code>Dr. Memory version 2.2.0 build 1 built on Jul  1 2019 00:42:20
  Windows version: WinVer=105;Rel=1909;Build=18363;Edition=Enterprise
  Dr. Memory results for pid 20424: "test.exe"
  Application cmdline: "bin/test.exe -callstack_max_frames 40 -malloc_max_frames 40 -free_max_frames 40"
  Recorded 117 suppression(s) from default C:\Program Files (x86)\Dr. Memory\bin\suppress-default.txt
  
  Error #1: UNADDRESSABLE ACCESS of freed memory: reading 0x01975230-0x01975234 4 byte(s)
  # 0 std::vector&lt;&gt;::~vector               [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/stl_vector.h:680]
  # 1 Comp1::~Comp1                        [C:/Tests/test.cpp:3]
  # 2 main                                 [C:/Tests/test.cpp:21]
  Note: @0:00:01.329 in thread 2068
  Note: next higher malloc: 0x01975258-0x01975268
  Note: 0x01975230-0x01975234 overlaps memory 0x01975228-0x01975238 that was freed here:
  Note: # 0 replace_operator_delete                              [d:\drmemory_package\common\alloc_replace.c:2975]
  Note: # 1 __gnu_cxx::new_allocator&lt;&gt;::deallocate               [C:/MSYS2-32/mingw32/include/c++/10.1.0/ext/new_allocator.h:133]
  Note: # 2 std::allocator_traits&lt;&gt;::deallocate                  [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/allocator.h:187]
  Note: # 3 std::_Vector_base&lt;&gt;::_M_deallocate                   [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/stl_vector.h:354]
  Note: # 4 std::vector&lt;&gt;::_M_default_append                     [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/vector.tcc:675]
  Note: # 5 std::vector&lt;&gt;::resize                                [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/stl_vector.h:940]
  Note: instruction: mov    0x04(%edx) -&gt; %ecx
  
  Error #2: UNADDRESSABLE ACCESS of freed memory: reading 0x0197522c-0x01975230 4 byte(s)
  # 0 std::vector&lt;&gt;::~vector               [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/stl_vector.h:680]
  # 1 Comp1::~Comp1                        [C:/Tests/test.cpp:3]
  # 2 main                                 [C:/Tests/test.cpp:21]
  Note: @0:00:01.447 in thread 2068
  Note: next higher malloc: 0x01975258-0x01975268
  Note: 0x0197522c-0x01975230 overlaps memory 0x01975228-0x01975238 that was freed here:
  Note: # 0 replace_operator_delete                              [d:\drmemory_package\common\alloc_replace.c:2975]
  Note: # 1 __gnu_cxx::new_allocator&lt;&gt;::deallocate               [C:/MSYS2-32/mingw32/include/c++/10.1.0/ext/new_allocator.h:133]
  Note: # 2 std::allocator_traits&lt;&gt;::deallocate                  [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/allocator.h:187]
  Note: # 3 std::_Vector_base&lt;&gt;::_M_deallocate                   [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/stl_vector.h:354]
  Note: # 4 std::vector&lt;&gt;::_M_default_append                     [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/vector.tcc:675]
  Note: # 5 std::vector&lt;&gt;::resize                                [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/stl_vector.h:940]
  Note: instruction: mov    (%edx) -&gt; %edx
  
  Error #3: UNADDRESSABLE ACCESS of freed memory: reading 0x01975234-0x01975238 4 byte(s)
  # 0 std::_Vector_base&lt;&gt;::~_Vector_base               [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/stl_vector.h:336]
  # 1 std::vector&lt;&gt;::~vector                           [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/stl_vector.h:683]
  # 2 Comp1::~Comp1                                    [C:/Tests/test.cpp:3]
  # 3 main                                             [C:/Tests/test.cpp:21]
  Note: @0:00:01.471 in thread 2068
  Note: next higher malloc: 0x01975258-0x01975268
  Note: 0x01975234-0x01975238 overlaps memory 0x01975228-0x01975238 that was freed here:
  Note: # 0 replace_operator_delete                              [d:\drmemory_package\common\alloc_replace.c:2975]
  Note: # 1 __gnu_cxx::new_allocator&lt;&gt;::deallocate               [C:/MSYS2-32/mingw32/include/c++/10.1.0/ext/new_allocator.h:133]
  Note: # 2 std::allocator_traits&lt;&gt;::deallocate                  [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/allocator.h:187]
  Note: # 3 std::_Vector_base&lt;&gt;::_M_deallocate                   [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/stl_vector.h:354]
  Note: # 4 std::vector&lt;&gt;::_M_default_append                     [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/vector.tcc:675]
  Note: # 5 std::vector&lt;&gt;::resize                                [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/stl_vector.h:940]
  Note: instruction: mov    0x08(%eax) -&gt; %edx
  
  Error #4: UNADDRESSABLE ACCESS of freed memory: reading 0x0197522c-0x01975230 4 byte(s)
  # 0 std::_Vector_base&lt;&gt;::~_Vector_base               [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/stl_vector.h:336]
  # 1 std::vector&lt;&gt;::~vector                           [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/stl_vector.h:683]
  # 2 Comp1::~Comp1                                    [C:/Tests/test.cpp:3]
  # 3 main                                             [C:/Tests/test.cpp:21]
  Note: @0:00:01.489 in thread 2068
  Note: next higher malloc: 0x01975258-0x01975268
  Note: 0x0197522c-0x01975230 overlaps memory 0x01975228-0x01975238 that was freed here:
  Note: # 0 replace_operator_delete                              [d:\drmemory_package\common\alloc_replace.c:2975]
  Note: # 1 __gnu_cxx::new_allocator&lt;&gt;::deallocate               [C:/MSYS2-32/mingw32/include/c++/10.1.0/ext/new_allocator.h:133]
  Note: # 2 std::allocator_traits&lt;&gt;::deallocate                  [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/allocator.h:187]
  Note: # 3 std::_Vector_base&lt;&gt;::_M_deallocate                   [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/stl_vector.h:354]
  Note: # 4 std::vector&lt;&gt;::_M_default_append                     [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/vector.tcc:675]
  Note: # 5 std::vector&lt;&gt;::resize                                [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/stl_vector.h:940]
  Note: instruction: mov    (%eax) -&gt; %ecx
  
  Error #5: UNADDRESSABLE ACCESS of freed memory: reading 0x0197522c-0x01975230 4 byte(s)
  # 0 std::_Vector_base&lt;&gt;::~_Vector_base               [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/stl_vector.h:335]
  # 1 std::vector&lt;&gt;::~vector                           [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/stl_vector.h:683]
  # 2 Comp1::~Comp1                                    [C:/Tests/test.cpp:3]
  # 3 main                                             [C:/Tests/test.cpp:21]
  Note: @0:00:01.504 in thread 2068
  Note: next higher malloc: 0x01975258-0x01975268
  Note: 0x0197522c-0x01975230 overlaps memory 0x01975228-0x01975238 that was freed here:
  Note: # 0 replace_operator_delete                              [d:\drmemory_package\common\alloc_replace.c:2975]
  Note: # 1 __gnu_cxx::new_allocator&lt;&gt;::deallocate               [C:/MSYS2-32/mingw32/include/c++/10.1.0/ext/new_allocator.h:133]
  Note: # 2 std::allocator_traits&lt;&gt;::deallocate                  [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/allocator.h:187]
  Note: # 3 std::_Vector_base&lt;&gt;::_M_deallocate                   [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/stl_vector.h:354]
  Note: # 4 std::vector&lt;&gt;::_M_default_append                     [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/vector.tcc:675]
  Note: # 5 std::vector&lt;&gt;::resize                                [C:/MSYS2-32/mingw32/include/c++/10.1.0/bits/stl_vector.h:940]
  Note: instruction: mov    (%eax) -&gt; %edx
  
  ===========================================================================
  FINAL SUMMARY:
  
  DUPLICATE ERROR COUNTS:
  
  SUPPRESSIONS USED:
  
  ERRORS FOUND:
        5 unique,     5 total unaddressable access(es)
        0 unique,     0 total uninitialized access(es)
        0 unique,     0 total invalid heap argument(s)
        0 unique,     0 total GDI usage error(s)
        0 unique,     0 total handle leak(s)
        0 unique,     0 total warning(s)
        0 unique,     0 total,      0 byte(s) of leak(s)
        0 unique,     0 total,      0 byte(s) of possible leak(s)
  ERRORS IGNORED:
        2 potential error(s) (suspected false positives)
           (details: C:\Users\david\AppData\Roaming\Dr. Memory\DrMemory-test.exe.20424.000\potential_errors.txt)
        8 unique,    14 total,  19443 byte(s) of still-reachable allocation(s)
           (re-run with "-show_reachable" for details)
  Details: C:\Users\david\AppData\Roaming\Dr. Memory\DrMemory-test.exe.20424.000\results.txt
  </code></pre>
  
  <p>Have I missed something with my program, or is this a case where DrMemory can't really work out what I'm doing?</p>