MySQL++ - 运行时检查失败 #2 - 变量周围的堆栈已损坏
我遇到了 MySQL++ 问题,迫切需要帮助。 我正在使用 Visual Studio 2010、MySQL++ v3.1.0 和 MySQL v5.1.59( x86 & x64 ); 所有库均已正确编译。由于编译器设置“Both (/RTC1,equiv. to /RTCsu) (/RTC1)”处于开启状态,此错误仅发生在 Debug 版本中。
编辑:我应该注意,这只发生在调试版本中。在发布中它就像一个魅力 我已将问题追溯到 mysqlpp_d.dll,由于引用计数,MySQL++ 对象在析构函数上崩溃。它抱怨无法访问引用计数器的内存,当它尝试减少它时,它崩溃了。至少我认为是这样的。
我尝试这样做是为了确保所有内容都以正确的顺序取消引用和删除(即使它无关紧要,但希望帮助我追踪真正的问题): http://pastebin.com/Ru0uYcy9
它崩溃了:
第一次机会异常位于 0x000007feeef5dd4c Launcher.exe 中的 (mysqlpp_d.dll):0xC0000005:访问冲突写入位置 0x000007feeeff5148。 Launcher.exe 中 0x000007feeef5dd4c (mysqlpp_d.dll) 处出现未处理的异常:0xC0000005:写入位置 0x000007feeeff5148 时出现访问冲突。
并在这里中断: http://pastebin.com/9Mfr7NwB
im having issues with MySQL++ and desperately need help.
I'm using Visual Studio 2010, MySQL++ v3.1.0 and MySQL v5.1.59( x86 & x64 );
All Library's have been compiled correctly. This error only occurs in Debug version due to the compiler setting "Both (/RTC1, equiv. to /RTCsu) (/RTC1)" being on.
Edit: I should note that this only happens in Debug version. In Release it works like a charm
I've tracked the problem back to the mysqlpp_d.dll, the MySQL++ object are crashing on there destructors due to reference counting. It complains about not being capable of accessing the memory of the ref counter, and when it tries to decrease it, it crashes. At least thats what I think happens.
I tried this to make sure everything gets derefrenced and removed in the correct order (even tho its irrelevant, but helped me track the true problem down I hope): http://pastebin.com/Ru0uYcy9
It crashes with:
First-chance exception at 0x000007feeef5dd4c (mysqlpp_d.dll) in Launcher.exe: 0xC0000005: Access violation writing location 0x000007feeeff5148.
Unhandled exception at 0x000007feeef5dd4c (mysqlpp_d.dll) in Launcher.exe: 0xC0000005: Access violation writing location 0x000007feeeff5148.
And breakes here:
http://pastebin.com/9Mfr7NwB
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这段代码有一个严重的错误:
您没有消耗所有结果集。在 MySQL 中,返回数据的存储过程至少返回两个单独的结果集:第一个是您请求的结果,第二个是有关调用本身的状态信息。请参阅 MySQL++ 源代码发行版中的
examples/multiquery.cpp
以了解处理此问题的正确方法。另请参阅 MySQL++ 用户手册中的第 3.16 节。这样做的主要后果是同一连接上的后续查询将失败。
我认为你的内存损坏实际上是次要影响,主要问题源于忽略 MySQL C API 的尝试告诉你你正在尝试在同一连接上运行两个重叠的查询,因为你没有消耗整个连接第一个结果集。从你发布的一小段代码中,我可以看到你忽略了返回的错误代码,所以如果你还禁用了 MySQL++ 异常,你的代码将完全忽略这个错误,并愉快地继续践踏所有它应该做的事情。 t。
顺便说一句,请丢失查询中的尾随分号。 C API 不需要它,并且可能会导致混乱,尤其是在面对多个查询时。仅使用分号来分隔单个查询中的多个语句。
This code has a serious bug:
You aren't consuming all the result sets. In MySQL, stored procedures that return data return at least two separate result sets: the first is the results you asked for, and the second is status information about the call itself. See
examples/multiquery.cpp
in the MySQL++ source distribution for the correct way to handle this. Also see section 3.16 in the MySQL++ user manual.The main consequence of this is that later queries on the same connection will fail.
I think your memory corruption is actually a secondary effect, and that the primary problem stems from ignoring the MySQL C API's attempts to tell you that you're trying to run two overlapping queries on the same connection, because you didn't consume the entire first result set. From what little code you've posted, I can see that you're ignoring returned error codes, so if you've also disabled MySQL++ exceptions, your code will completely ignore this error and blithely go on to stomp all over things it shouldn't.
By the way, please lose the trailing semicolon on the query. It isn't needed with the C API, and can cause confusion, especially in the face of multi-queries. Use semicolons only to separate multiple statements in a single query.