title: scalar deleting destructor crashes
body: <p>I am writing a little C++ program related to HTTP, but it always crashes, I attached WinDbg to it, and the stack is as below(I omitted the <code>RetAddr</code> and other irrelevant columns):</p>
  
  <pre><code>MSVCR120D!operator delete+0xa0 [f:\dd\vctools\crt\crtw32\misc\dbgdel.cpp @ 52]
  xproxy!HttpRequestInitial::`scalar deleting destructor'+0x53
  xproxy!&lt;lambda_e1d25e8e9bf0ff4ef442e9ed8e6e27a0&gt;::operator()+0x7c [d:\xproxy\http_container.h @ 61]
  xproxy!std::_For_each&lt;HttpObject * __ptr64 * __ptr64,&lt;lambda_e1d25e8e9bf0ff4ef442e9ed8e6e27a0&gt; &gt;+0x56 [d:\sdts\vs2013\vc\include\algorithm @ 24]
  xproxy!std::for_each&lt;std::_Vector_iterator&lt;std::_Vector_val&lt;std::_Simple_types&lt;HttpObject * __ptr64&gt; &gt; &gt;,&lt;lambda_e1d25e8e9bf0ff4ef442e9ed8e6e27a0&gt; &gt;+0x15e [d:\sdts\vs2013\vc\include\algorithm @ 35]
  xproxy!HttpContainer::reset+0x8e [d:\xproxy\http_container.h @ 62]
  </code></pre>
  
  <p>The code will call <code>HttpContainer::reset()</code>, this function will delete all objects it stored, so the destructor of these objects will be called, and the delete operation causes the crash, but I have carefully checked my code, I cannot find why it crashes, since destructor of <code>HttpRequestInitial</code> does nothing, and also its parent classes.</p>
  
  <p>The related code is as below:</p>
  
  <pre><code>class HttpContainer {
  public:
      virtual ~HttpContainer() {
          for(auto it = objects_.begin(); it != objects_.end(); ++it)
              if(*it) delete *it;
      }
  
      virtual void reset() {
          std::for_each(objects_.begin(), objects_.end(),
                        [](HttpObject* object) { if(object) delete object; });
          objects_.clear();
      }
  
      // ...
  
  private:
      std::vector&lt;HttpObject*&gt; objects_;
  };
  
  // HttpRequestInitial inherits from HttpInitial
  // HttpInitial inherits from HttpObject
  class HttpRequestInitial : public HttpInitial {
  public:
      HttpRequestInitial() : HttpInitial(kHttpRequestInitial) {}
  
      virtual ~HttpRequestInitial() {}
  
      // ...
  
  private:
      std::string method_;
      std::string uri_;
  };
  </code></pre>
  
  <p>I can only find <a href="https://stackoverflow.com/questions/4948339/why-is-a-scalar-deleting-destructor-being-called-as-a-result-of-vector-delete-on">this question</a> on SO similar to mine, but its answer says it is a compiler bug, but my compiler is VS2013, and I am not using an array but a vector. Any ideas?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Thanks for your quick update. Yeah, I admit that I should use smart pointer instead, but now I am curious "the why". The object is dynamically allocated and inserted into the instance of <code>HttpContainer</code>, by using a <code>AppendObject(HttpObject *)</code> method I omitted, and it happens in the exe file(a class called <code>Session</code>), and not from a dll, the code is as below:</p>
  
  <pre><code>void Session::OnClientDataReceived(const boost::system::error_code&amp; e) {
      HttpObject *object = new HttpRequestInitial();
      //... set its property here
      request_-&gt;AppendObject(object);
  }
  </code></pre>