连接到MySQL时出现分段错误
Segmentation fault when connecting to MySQL
我在一个大项目中有这样的代码,该项目连接到MySQL数据库,但不起作用:
boost::shared_ptr<sql::Connection> connection;
sql::Driver *driver = get_driver_instance();
assert(driver != 0);
std::string server = "servname", user = "pietro", password = "abc";
try
{
connection.reset(driver->connect(server, user, password));
assert(connection != 0);
if(connection->isClosed() == false) // <-- segmentation fault
{
}
}
我在指示的地方得到了一个分段错误(所有参数都是有效的)
然而,同样的代码也适用于测试项目。
使用调试器进入sql::Connection::isClosed()
成员函数,我没有获得有关可能原因的信息;这是我的位置:
mysql-connector-c++-1.0.5/deriver/mysql_connection.cpp-线路430
/* {{{ MySQL_Connection::checkClosed() -I- */
void
MySQL_Connection::checkClosed()
{
CPP_ENTER_WL(intern->logger, "MySQL_Connection::checkClosed");
if (!intern->is_valid) {
throw sql::SQLException("Connection has been closed");
}
}
这个checkClosed()
函数在connection.reset()
之前成功执行了七次。"intern
"指针的值在此阶段不会更改,也不为空。
当我检查连接是否关闭时,checkClosed()
函数将再次运行。现在"intern
"指针值为0x8,这是我无法访问的位置。
这里我得到一个SIGSEGV
,分段错误。
如果你想要反汇编的代码,请告诉我。。。
平台:
MySQL 5.x
MySQL连接器/C++1.0.5
Linux-OpenSuse 11.4
第页。S.:我注意到shared_ptr
的所有成员功能都按预期工作:
connection.get(); // = 0x8fb4a0
connection.use_count(); // = 1
connection.unique(); // = 1
而在指向对象上执行的所有调用都会导致分段错误(SIGABRT):
connection->getClientInfo();
connection->isClosed();
要么连接被删除,要么内存损坏。使用valgrind查找答案
相关文章:
- 在某些循环内使用vector.push_back时出现分段错误
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- 当我的阵列太大时出现分段错误
- 分段错误当我试图运行程序时出错
- 在c++中初始化矩阵时出现分段错误(核心转储)
- 尝试使用集合函数时出现分段错误
- 我无法缩小此分段错误的原因
- g++的分段错误(在NaN上使用to_string两次时)
- 我是如何在这段代码中出现分段错误的
- 创建结构的数组时遇到分段错误
- 在c++中键入向量中的所有值后,得到分段错误(核心转储)
- 在 c++ 中实现 Trie 时出现分段错误
- 为什么 fstream 在打开带有格式的文件时会导致分段错误?
- 为什么我遇到分段错误?
- 动态类的分段错误(家庭作业问题)
- 分段错误 - 读取初始化指针的数组
- 如何摆脱C ++中的分段错误错误?
- 使用 CTYPE 时出现分段错误
- 为什么代码给出分段错误?