I think we should have that delete statement in OpenWireProducerInfo destructor to avoid memory leak. To avoid Segmentation Fault from exception handling in OpenWireConnector::createProducer(), remove "delete producerInfo" statements, because "delete producer" already takes care of deleting producerInfo. Gavin123
gavin123 wrote: > > I am writing a ActiveMQ-Cpp client using ActiveMQ-CPP version 2.1; This > client application runs on Linux machine (Linux version > 2.6.12-1.1381_FC3) > An ActiveMQ Message Broker( version 4.2 ) process runs on another linux > machine. > > If my application tries to create a producer while the ethernet connection > between my client machine and the message broker machine disconnected, > then I my client application crashes with the following error message: > > //begin error message > Segmentation fault > //end error message > > Running gdb debugger on my client application, I see the following error: > > //begin gdb error message > Program received signal SIGSEGV, Segmentation fault. > 0x009bad3c in > activemq::connector::openwire::OpenWireConnector::createProducer ( > this=0x83ead30, destination=0x83ec328, session=0x83ebf10) > at activemq/connector/openwire/OpenWireConnector.cpp:752 > 752 delete producerInfo; > //end gdb error message > > Inside activemq::connector::openwire::OpenWireConnector::creatProducer() > function, I notice these following lines of codes: > //inside the function OpenWireConnector::createProducer() > ProducerInfo* OpenWireConnector::createProducer( > const cms::Destination* destination, > connector::SessionInfo* session ) > throw ( ConnectorException ) > { ... > 706: producer = new OpenWireProducerInfo( this ); > ... > 709: producerInfo = new commands::ProducerInfo(); > 710: producer->setProducerInfo( producerInfo ); > ... > 750: }catch( ConnectorException& ex ) { > 751: delete producer; > 752: delete producerInfo; > ... > } > //end of createProducer() > line 710: inits the producer internal pointer to producerInfo pointer. > when an exception is caught, line 751: delete the producer which will call > OpenWireProducerInfo destructor, which in turns deletes the producer > internal pointer. This will deallocate the memory that producerInfo > pointer is pointing to. This causes line 752: delete producerInfo crash > the application with error "Segmentation Fault" > > Take a look at OpenWireProducerInfo destructor > //inside OpenWireProducerInfo.h > virtual ~OpenWireProducerInfo() { > this->close(); > delete producerInfo; > } > //end destructor > > Should we have to delete producerInfo? > > Does anybody know of a fix that doesn't affect other classes? > > Thanks > Gavin123 > > > > -- View this message in context: http://www.nabble.com/ActiveMQ-CPP-client-crashes-creating-producers-thru-a-broken-ethernet-link-with-ActiveMQ-Message-Broker-tf4741138s2354.html#a13558279 Sent from the ActiveMQ - User mailing list archive at Nabble.com.