title: Who takes ownership of the IErrorInfo?
body: <p>We use Native COM support in our code havily. Everything's fine except that we don't like the fact that on error _com_raise_error() is called which throws a _com_error exception. Since we have our own hierarchy of exceptions catching this _com_error is inconvenient - it's not in our hierarchy and even doesn't inherit from std::exception.</p>
  
  <p>So we need to override the _com_raise_error(). It's easy by itself - just define it in our code, the linker will link with it.</p>
  
  <p>However is unclear who owns the IErrorInfo. The signature is</p>
  
  <pre><code>void __stdcall _com_raise_error( HRESULT hr, IErrorInfo* info );
  </code></pre>
  
  <p>So whoever calls the function would be responsible for calling IErrorInfo::Release() after the function returns. But how would the function return at all if we throw an exception in it and the control would transfer somewhere else?</p>
  
  <p>I checked - called AddRef(), then Release() immediately upon entry into that function - the reference counter is 1. Later we pass ownership to the constructed exception object - it calls AddRef() in its constructor and Release() in destructor. I suppose this is incorrect since the AddRef() will increase the reference count to 2 but then only one Release() will be called (in the exception destructor).</p>
  
  <p>Am I correct that the AddRef() in the constructor will cause a memory leak or is there some internal mechanism that doesn't allow IErrorInfo objects to leak at all?</p>