Resultset::getString(string) crash.
This is on Visual Studio 2008 on a dual-core, 32 bit Vista machine. In the debug code (using the source code compiled with CMake) this runs fine, but in Release mode this bombs:
void getFromDB(vector<string>& dates) {
...
sql::Resultset res = stmt->executeQuery("SELECT FROM ...");
while (res->next()) {
string date = res->getString("date");
dates.push_back(date);
} // <<< crashing here (line 56)
delete res;
}
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:
HEAP[sa-ms-release.exe]: Invalid address specified to RtlFreeHeap( 024E0000, 001C4280 ) Windows has triggered a breakpoint in sa-ms-release.exe.
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
> sa-ms-release.exe!free(void * pBlock=0x001c4280) Line 110 C
sa-ms-release.exe!std::allocator<char>::deallocate(char * _Ptr=0x001c4280, unsigned int __formal=32) Line 140 + 0x9 bytes C++
sa-ms-release.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Tidy(bool _Built=true, unsigned int _Newsize=0) Line 2158 C++
sa-ms-release.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::~basic_string<char,std::char_traits<char>,std::allocator<char> >() Line 907 C++
sa-ms-release.exe!StyleData:: getFromDB( std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > > & dates) Line 56 + 0x69 bytes C++
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.
If I replace
string date = res->getString("date")
with
string date = string ("2008-11-23");
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.
The header files are read from C++ options: /I "C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\include"
Linker options: /LIBPATH:"C:\Program Files\MySQL\MySQL Connector C++ 1.0.5\lib\opt" ... mysqlcppconn.lib
And the DLL loaded is (in the PATH where I copied it from its installation directory where the connector put it): mysqlcppconn.dll C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqlcppconn.dll N/A N/A Symbols not loaded. 4 4/17/2009 15:16 74520000-74591000 [6492] sa-ms-release.exe: Native
Thanks for your help!