Segmentation Fault Fail?
Segmentation Fault Fail?
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -177935456 (LWP 5483)]
0xf79ff2ca in activemq::core::ActiveMQSessionExecutor::dispatch (this=0xf4b04bc0,
dispatch=@0xf564e240) at activemq/core/ActiveMQSessionExecutor.cpp:129
129 activemq/core/ActiveMQSessionExecutor.cpp: No such file or directory.
in activemq/core/ActiveMQSessionExecutor.cpp
Current language: auto; currently c++
我怎么能解决这个问题?你需要更多的代码吗?我不知道哪里出错了?我怎样才能找到失败的地方?
转储到哪里?
编辑:
下面是代码:
std::string ActiveMQWrapper::get(){
Connection* connection;
Session* session;
Destination* destination;
MessageConsumer* consumer;
try {
std:string brokerURI = "tcp://localhost:61613?wireFormat=stomp";
auto_ptr<ConnectionFactory> connectionFactory(ConnectionFactory::createCMSConnectionFactory( brokerURI ) );
connection = connectionFactory->createConnection();
connection->start();
session = connection->createSession( Session::AUTO_ACKNOWLEDGE );
destination = session->createQueue( "TEST.Prototype" );
consumer = session->createConsumer( destination );
TextMessage* textMessage =
dynamic_cast< TextMessage* >( consumer->receive() );
string text = "";
if( textMessage != NULL ) {
text = textMessage->getText();
} else {
text = "NOT A TEXTMESSAGE!";
}
try{
if( destination != NULL ) delete destination;
}catch (CMSException& e) { e.printStackTrace(); }
destination = NULL;
try{
if( consumer != NULL ) delete consumer;
}catch (CMSException& e) { e.printStackTrace(); }
consumer = NULL;
// Close open resources.
try{
if( session != NULL ) session->close();
if( connection != NULL ) connection->close();
}catch (CMSException& e) { e.printStackTrace(); }
// Now Destroy them
try{
if( session != NULL ) delete session;
}catch (CMSException& e) { e.printStackTrace(); }
session = NULL;
try{
if( connection != NULL ) delete connection;
}catch (CMSException& e) { e.printStackTrace(); }
connection = NULL;
return text.c_str();
} catch( CMSException& e ) {
e.printStackTrace();
}
}
我在寻找这个问题的答案时偶然发现了这个问题,并发现了正确的解决方案。ActiveMQ-CPP库需要首先正确初始化:
activemq::library::ActiveMQCPP::initializeLibrary();
完成后别忘了关闭它:
activemq::library::ActiveMQCPP::shutdownLibrary();
它实际上是OP链接到的网页的一部分:http://activemq.apache.org/cms/example.html
从您围绕删除的测试(这是完全不必要的,顺便说一句,NULL上的删除是完美定义的)我收集connection
等可能是NULL。然而,在上面,您在使用它们之前没有检查NULL。因此,可能其中一个是NULL,因此您的访问会导致分割错误。
也:是从ConnectionFactory返回的指针::createCMSConnectionFactory分配与new
?因为否则将它们存储在auto_ptr
中是不正确的事情。
此外,类型ConnectionFactory
是在实例化auto_ptr
的地方定义的(而不是仅仅(向前)声明的)吗?因为在不完整的类型上实例化auto_ptr
(比如只声明了,还没有定义的类型)是未定义的行为,也可能导致分段错误。
这些都是我看到的可能性。仅使用您展示的代码无法说明更多内容。您真的应该用调试器一步完成它,看看分段错误发生在哪里。
相关文章:
- Seg Fault Issue C++ (file IO / getline)
- Problems with std::cin.fail()
- 示例外壳应用程序显示的 V8 "segmentation fault (core dumped)"错误
- 为什么我的C++代码中出现'Segmentation Fault: 11'行?
- 给定一个整数数组,需要在Max_Heap上运行操作。得到错误"segmentation fault",有什么想法吗?(C++)
- 了解 cin.fail() 和 cin.clear语言 - Vector 追加程序
- 循环时无法进入:"Segmentation fault"
- cin.fail() not returning true
- OpenGL "Segmentation fault"错误
- cin.fail 在输入数字和字母时不起作用
- 如何修复访问动态数组中结构中的字符串变量时"segmentation fault (core dumped)"错误
- 如何修复 C++ 中的'Segmentation fault'错误
- unordered_map segment fault
- 创建一个简单的类及其变量和函数不断返回" segmentation fault (core dumped)"、C++
- 我如何检查CIN.FAIL(),但仍使用Ctrl D到达文档的结尾
- OpenCV UIImageToMat linker fail in xcode
- CIN.FAIL无法按预期工作
- 在 Mac OS 上遇到的"Segmentation fault: 11" [C++]
- Qt WebEngine on fail
- Segmentation Fault Fail?