分段故障失败? [英] Segmentation Fault Fail?

查看:422
本文介绍了分段故障失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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++

如何解决这个问题?你需要更多的代码吗?我不知道它失败了吗?如何找到它失败的地方?

How can i fix this? do you need more code? I dont know where it fails? how can i find where it fails?

它转储到哪里?

编辑:

此处是代码:


here is the code:

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();
    }
}


推荐答案

你的测试围绕删除(这是完全不必要的BTW,删除对NULL完美定义)我认为连接等可能为NULL。但是,上面你不使用之前检查NULL。因此,也许其中一个是NULL,你的访问因此给出一个分割错误。

From your tests around the delete (which are completely unneccessary BTW, delete on NULL is perfectly defined) I gather that connection etc. could be NULL. However, above you don't check for NULL before using them. So maybe one of them is NULL, and your access therefore gives a segmentation fault.

还有:从ConnectionFactory :: createCMSConnectionFactory返回的指针分配 new ?因为否则将它们存储在 auto_ptr 中是不正确的。

Also: Are the pointers returned from ConnectionFactory::createCMSConnectionFactory allocated with new? Because otherwise storing them in an auto_ptr is not the right thing to do.

在你实例化 auto_ptr 的时候,c $ c> ConnectionFactory 因为在不完整的类型(例如只声明,尚未定义的类型)上实例化 auto_ptr 是未定义的行为,并且还可能导致分段错误。

Moreover, is the type ConnectionFactory defined (as opposed to just (forward) declared) at the point where you instantiated the auto_ptr? Because instantiating auto_ptr on an incomplete type (such as one which was only declared, not yet defined) is undefined behaviour and might also lead to a segmentation fault.

这是我看到的可能性。没有办法说只有你显示的代码更多。你真的应该使用调试器单步执行,看看分段错误发生的位置。

Those are the possibilities I see. There's no way to say more with only the code you showed. You really should single-step through it with a debugger and see where the segmentation fault occurs.

这篇关于分段故障失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆