std::string crashing while iterating on mySQL connector query results - c++

I'm trying to get a std::string from my database using mysql connexion
Here is the simple code:
sql::Statement *stmt = con->createStatement();
sql::ResultSet *res = stmt->executeQuery("SELECT * FROM test.new_table");
while (res->next()) {
std::string somestring = res->getString("idnew_table");
} //crashes here
delete res;
delete stmt;
So, the executeQuery is fine, I enter the loop, and if I break, the expected results are in somestring. After the somestring declaration, I step foward to the end of the loop, and it crashes before the next iteration!
Here is the call stack:
> msvcp100d.dll!std::_Lockit::_Lockit(int kind) Line 64 + 0x14 bytes C++
msvcp100d.dll!std::_Container_base12::_Orphan_all() Line 200 C++
CM.dll!std::_String_val<char,std::allocator<char> >::~_String_val<char,std::allocator<char> >() Line 478 + 0xb bytes C++
CM.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::~basic_string<char,std::char_traits<char>,std::allocator<char> >() Line 755 + 0xf bytes C++
CM.dll!DAL::GetInfo() Line 45 + 0xc bytes C++
Output:
First-chance exception at 0x1038ad4a (msvcp100d.dll) in CMLauncher.exe: 0xC0000005: Access violation reading location 0xccccccd0.
Unhandled exception at 0x76f615de in CMLauncher.exe: 0xC0000005: Access violation reading location 0xccccccd0.
First-chance exception at 0x76f5016e in CMLauncher.exe: 0x00000000: The operation completed successfully.
Unhandled exception at 0x76f615de in CMLauncher.exe: 0x00000000: The operation completed successfully.
So it looks like I have some uninitialized memory somewhere in the C++ runtime lib...
It look like it's crashing in the std::string destructor, which kind of makes sense because it crashes when the scope of the string is done...
My best guess is that libmysql is using an older version of the C++ runtime (say msvcp90d.dll) and that it's clashing with the new one... does that even make sense?
I'm under windows 7, using mySQL Server 5.5, VS2010 Pro. all in 32bits. thx! I'll be happy to post any mroe information that is needed.
Edit: Before anyone else reads DumbCoders comment:
MySQL Connector example
The documentation specifies that both the statement and the resultSet have to be deleted.

This problem seems just like yours here.

Related

VisualC++ 2010 Is there a way to find out more details surrounding unhandled exception error

A windows application I am working on contains the following code:
if (_camStar->GetSortedContainersFromOpsView("CAD", false, containers, errorMessage)) {
error = "";
if (!containers.empty())
{
desc = QString::fromStdString(containers[0]->masterProductDescription);
prodname = QString::fromStdString(containers[0]->productName).trimmed();
res = QString::fromStdString(containers[0]->ctnrName);
}
}
else
{
error = QString::fromStdString(errorMessage);
}
_camStar is a variable from an external header file to which I am initializing here via:
_camStar = new CamstarInterface(host, port, username, password, workstation);
CamstarInterface is an interface that's declared in that same header file. When I run the program in Debug mode, I am presented with:
Unhandled Exception at 0xx5c84337d (msvcp100d.dll) in initializer.exe: 0xC0000005: Access violation reading location 0xffffffffffffffff.
and it breaks in xutility (I believe its used by Qt) in the function Orphan_all(). When I run the program in Release mode, everything works fine.
How would I go about digging into the exception to see what exactly it doesn't like?
EDIT: The xutility file is shown when I have a try/catch surrounding the code above and is opened when I return the QString res variable. Otherwise I see the following unhandled exception on the GetSortedContainersFromOpsView line:
Unhandled Exception at 0x000007fefce7a06d in initializer.exe: 0xC0000005: Access violation writing location 0x00000000004ffff8.
No other file is opened. The stack trace looks like so:
initializer!initializer::GetNextImplant(QString& error) Line 347 + 0x5e bytes
initializer!initializer::Process() Line 298 + 0x17 bytes
initializer!initializer::Start() Line 169
initializer!main(int argc, char**argv) Line 18
initializer!WinMain() line 131 + 0x16 bytes
initializer!__tmainCRTStartup() line 547 + 0x42 bytes
initializer!WinMainCRTStartup() Line 371
At line 347 is the GetSortedContainersFromOpsView call. What should I do? It doesn't really seem to give me much.
The issue was indeed related to one of the dependencies. One of the dependencies has invalid references due to a .NET 4.5/Visual Studio 2010 issue. Removing and re-adding all of those references in the dependency project, and rebuilding the library fixed the issue.

Access Violation in Qt postEvent

I have an application that is starting to throw fits at various points. It was written ages ago using one of the first versions of the Qt library. Love to update it but that's not in the cards yet. While testing a part of the app, I received an unexpected crash:
Unhandled exception at 0x00a220db in MyApp.exe:
0xC0000005: Access violation reading location 0x00000000.
The application code that I can see (the Qt lib source code is not available for debugging so it's just a disassembly).
MyEvent myEvent = new MyEvent(str1, int, str2);
QApplication::postEvent(parent(), myEvent);
Call stack at the affected area:
MyApp.exe!QGList::append() + 0x6b bytes
MyApp.exe!QList<QPostEvent>::append() + 0x2f bytes
MyApp.exe!QApplication::postEvent() + 0x55a bytes
> MyApp.exe!SomeClass::writeTestName(const char * format=0x00f6c2b8, ...) Line 386 + 0x15 bytes
If I examine myEvent and parent(), both appear to be valid. What is the postEvent method adding my event to and, assuming it's a Qt internal, which it appears to be, why would it fail - is there some initialization that needs to be done that the original programmer might have missed?

COleException at memory location for COleSafeArray

I'm trying to work with the following sample code that was provided to me
// select the Access levels from access level list
BSTR myBstr = SysAllocString(L"Hello World");
COleSafeArray saAccessLevels;
VARIANT vAccls;
saAccessLevels.CreateOneDim(VT_BSTR, 1);
saAccessLevels.PutElement(0, myBstr); // <-- Error after this line
vAccls = saAccessLevels.Detach();
The Visual C++ debugger breaks at the line noted in the above comment and I get the following errors:
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\olemisc.cpp(423) : AppMsg - Warning: constructing COleException, scode = E_INVALIDARG ($80070057).
First-chance exception at 0x75371D4D in MyApplication.exe: Microsoft C++ exception: COleException at memory location 0x0057FC58.
Unhandled exception at 0x75371D4D in MyApplication.exe: Microsoft C++ exception: COleException at memory location 0x0057FC58.
I am not familiar with C++ programming. What am I doing wrong?
You're using the PutElement method incorrectly. The first parameter is a pointer to an array of indices. Have a look at MSDN.

Access violation on sqlite3_open API call

I am writing a server application with sqlite3 and c++. My problem occurs in the following line: int connect = _sqlite3_open(database_sqlite_file, &db);
In the MSVC++ logs I get these notes:
Unhandled exception at 0x74ABCB49 in Fantasia_Database.exe: 0xC0000005: Access violation executing location 0x00000000.
Anyone know the source of this error, what am I doing wrong?

Unhandled exception while assigning strings. C++

I'm using Visual Studio 2012 Express and I write in c++.
I have a rather weird problem with my code.
void CMap::loadMap(const std::string &MapName)
{
m_MapName = MapName; // This line is causing an error
loadMap();
}
While it compiles succesfully, it crashes on that line when I run it.
Unhandled exception at 0x003A10FC (msvcr110d.dll) in MyAdventure.exe: 0xC0000005: Access violation writing location 0xFEEEFEEE.
That's what it says. When i click Break, it directs me to that line in memcpy.asm
mov [edi],al ;U - write second byte to destination
CMap is a class which has
std::string m_MapName;
as it's member.
I've also tried to compile my code in Visual Studio 2010 Express and it works fine without any problems. I'd really want to use VS 2012 though, so I'd really like some help.
Thanks for any help.