Note that there are some explanatory texts on larger screens.

plurals
  1. POMemory corrupt in adding string to vector<string> loop
    primarykey
    data
    text
    <p>This is on Visual Studio 2008 on a dual-core, 32 bit Vista machine. In the debug code this runs fine, but in Release mode this bombs:</p> <pre><code>void getFromDB(vector&lt;string&gt;&amp; dates) { ... sql::Resultset res = stmt-&gt;executeQuery("SELECT FROM ..."); while (res-&gt;next()) { string date = res-&gt;getString("date"); dates.push_back(date); } // &lt;&lt;&lt; crashing here (line 56) delete res; } </code></pre> <p>The MySQL C++ connector has this method in it's ResultSet:</p> <pre><code>virtual std::string getString(const std::string&amp; columnLabel) const = 0; </code></pre> <p>For some reason in the release compiled (against a MySQL C++ connector DLL) this crashes at the end of the loop with a heap corruption:</p> <blockquote> <p>HEAP[sa-ms-release.exe]: Invalid address specified to RtlFreeHeap( 024E0000, 001C4280 ) Windows has triggered a breakpoint in sa-ms-release.exe.</p> </blockquote> <pre><code> ntdll.dll!_RtlpBreakPointHeap@4() + 0x28 bytes ntdll.dll!_RtlpValidateHeapEntry@12() + 0x713e8 bytes ntdll.dll!_RtlDebugFreeHeap@12() + 0x9a bytes ntdll.dll!@RtlpFreeHeap@16() + 0x145cf bytes ntdll.dll!_RtlFreeHeap@12() + 0xed5 bytes kernel32.dll!_HeapFree@12() + 0x14 bytes &gt; sa-ms-release.exe!free(void * pBlock=0x001c4280) Line 110 C sa-ms-release.exe!std::allocator&lt;char&gt;::deallocate(char * _Ptr=0x001c4280, unsigned int __formal=32) Line 140 + 0x9 bytes C++ sa-ms-release.exe!std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt;::_Tidy(bool _Built=true, unsigned int _Newsize=0) Line 2158 C++ sa-ms-release.exe!std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt;::~basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt;() Line 907 C++ sa-ms-release.exe!StyleData:: getFromDB( std::vector&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt;,std::allocator&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &gt; &gt; &amp; dates) Line 56 + 0x69 bytes C++ </code></pre> <p>I think I may be violating some basic C++ rule that causes the destructor to be called on a string I want to preserve inside the vector.</p> <p>If I replace</p> <pre><code>string date = res-&gt;getString("date") </code></pre> <p>with </p> <pre><code>string date = string ("2008-11-23"); </code></pre> <p>everything works fine. It seems to have to do with the string returned from the MySQL C++ Connector getString() method. The returned string is destroyed and that causes the problem, I guess. But more likely something else is wrong. I am using the release (opt) MySQL connector.</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.
 

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