0
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?

where does it dump to ?

EDIT:
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();
    }
}
ildjarn
  • 62,044
  • 9
  • 127
  • 211
DarthVader
  • 52,984
  • 76
  • 209
  • 300
  • 1
    Yes, we will need more code. A good IDE and debugger can show you the stack trace. Some things to keep an eye out for are off-by-one errors and simply trying to access unallocated memory. – Maxpm Nov 15 '11 at 23:18
  • IDE is VIM and no gdb was the debugger. – DarthVader Nov 15 '11 at 23:20
  • 1
    What are you catching? Do any of those destructors actually throws `CMSException`? – K-ballo Nov 15 '11 at 23:22
  • I dont have a destructor. i made a class into a function. so i have to clean up no? – DarthVader Nov 15 '11 at 23:23
  • @DarthVader : What he means is that any destructor that throws is fundamentally broken, so wrapping up your `delete`s in `try..catch` blocks hints at Very Bad Things about the implementations of `Connection`, `Session`, `Destination`, etc. – ildjarn Nov 16 '11 at 00:02
  • http://activemq.apache.org/cms/example.html this is the code base. – DarthVader Nov 16 '11 at 00:06

2 Answers2

1

I stumbled across this when searching for the answer to this problem and discovered the correct solution. The ActiveMQ-CPP library needs to be initialized properly first:

activemq::library::ActiveMQCPP::initializeLibrary();

And don't forget to shut it down when finished:

activemq::library::ActiveMQCPP::shutdownLibrary();

It is actually part of the webpage that the OP linked to: http://activemq.apache.org/cms/example.html

Jon
  • 2,502
  • 4
  • 21
  • 23
-1

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.

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.

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.

celtschk
  • 19,311
  • 3
  • 39
  • 64
  • Well, since I don't know the interface of the library, I can't tell for sure if you are supposed to delete or not; for `connection`, `destination`, `session` and `user` I'm however pretty sure that you should. However, to be completely sure you need to check with the documentation (pointers don't *need* to point to memory allocated with `new`). But what is completely unnecessary is to check for NULL before deleting (i.e. instead of `it (foo!=NULL) delete foo;` just write `delete foo;` without testing for NULL). However you *should* test for NULL (but don't) before *using* those pointers. – celtschk Nov 16 '11 at 00:02