Note that there are some explanatory texts on larger screens.

plurals
  1. POFinding memory allocation error
    primarykey
    data
    text
    <p>I'm getting memory allocation errors (and a subsequent crash) on the following simplified code:</p> <pre><code>std::wstring myKey = L"str_not_actually_constant"; MyType obj; Read( obj ); std::map&lt;std::wstring, MyType&gt; myMap; myMap[myKey] = obj; // Sometimes allocation error (1) ... Read( MyType&amp; obj ) { obj.member1 = ReadFromFuncThatMayBeProblem(); obj.member2 = ReadFromFuncThatMayBeProblem(); // Sometimes allocation error (2) /* more members */ } ... void operator =( const MyType&amp; source ) { if( this != &amp;source ) { member1 = source.member1; // std::wstring member2 = source.member2; // Usually (1) happen on the second member. // std::wstring /* more members */ } } </code></pre> <p>Either (1) or (2) occur.</p> <p>Now, if I simply continue on regardless of the error (with the debugger), the value is indeed entered in the map.</p> <p>I don't know if ReadFromFuncThatMayBeProblem() is the culprit but it's a fairly complex function that I cannot devulge here.</p> <p>Also, this is code that has worked (or at least appeared to work) before other sections of the application was ported to use OpenSSL. I don't know if that may have had any effect here, though.</p> <p>So, what can I do to track down this allocation error, since I'm presuming that the above code is not in fact the problem?</p> <p>Edit: More info: There is no dtor for MyType. </p> <p>However, MyType has a member of type SecondType that has a void* member. This is being deleted and null'd in that type's destructor. The constructor uses m_pData = new std::wstring( <em>( (std::wstring</em> )source.m_pData) ); for strings. (And similar for other data types). Could that be an issue? (delete static_cast&lt; std::wstring* >( m_pData );)</p> <p>The other member types of MyType are std::wstring, unsigned long, bool, enum, structs (timeb among them) and SecondType. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload