You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2010/05/20 21:38:34 UTC
svn commit: r946771 - in
/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net:
ServerSocket.cpp Socket.cpp
Author: tabish
Date: Thu May 20 19:38:33 2010
New Revision: 946771
URL: http://svn.apache.org/viewvc?rev=946771&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQCPP-140
Fix some potential memory leaks in constructors that throw exceptions
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ServerSocket.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Socket.cpp
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ServerSocket.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ServerSocket.cpp?rev=946771&r1=946770&r2=946771&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ServerSocket.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/ServerSocket.cpp Thu May 20 19:38:33 2010
@@ -48,13 +48,13 @@ ServerSocket::ServerSocket( int port )
throw( decaf::io::IOException, decaf::lang::exceptions::IllegalArgumentException ) :
impl(NULL), created(false), closed(false), bound(false) {
- this->impl = this->factory != NULL ? factory->createSocketImpl() : new TcpSocket();
-
if( port < 0 ) {
throw IllegalArgumentException(
__FILE__, __LINE__, "Port value was invalid: %d", port );
}
+ this->impl = this->factory != NULL ? factory->createSocketImpl() : new TcpSocket();
+
this->setupSocketImpl( port, getDefaultBacklog(), NULL );
}
@@ -63,13 +63,13 @@ ServerSocket::ServerSocket( int port, in
throw( decaf::io::IOException, decaf::lang::exceptions::IllegalArgumentException ) :
impl(NULL), created(false), closed(false), bound(false) {
- this->impl = this->factory != NULL ? factory->createSocketImpl() : new TcpSocket();
-
if( port < 0 ) {
throw IllegalArgumentException(
__FILE__, __LINE__, "Port value was invalid: %d", port );
}
+ this->impl = this->factory != NULL ? factory->createSocketImpl() : new TcpSocket();
+
this->setupSocketImpl( port, backlog, NULL );
}
@@ -78,13 +78,13 @@ ServerSocket::ServerSocket( int port, in
throw( decaf::io::IOException, decaf::lang::exceptions::IllegalArgumentException ) :
impl(NULL), created(false), closed(false), bound(false) {
- this->impl = this->factory != NULL ? factory->createSocketImpl() : new TcpSocket();
-
if( port < 0 ) {
throw IllegalArgumentException(
__FILE__, __LINE__, "Port value was invalid: %d", port );
}
+ this->impl = this->factory != NULL ? factory->createSocketImpl() : new TcpSocket();
+
this->setupSocketImpl( port, backlog, ifAddress );
}
@@ -92,7 +92,6 @@ ServerSocket::ServerSocket( int port, in
ServerSocket::~ServerSocket() {
try{
close();
-
delete this->impl;
}
DECAF_CATCH_NOTHROW( Exception )
@@ -119,6 +118,8 @@ void ServerSocket::setupSocketImpl( int
this->impl->listen( backlog > 0 ? backlog : getDefaultBacklog() );
} catch( IOException& ex ) {
close();
+ delete this->impl;
+ this->impl = NULL;
throw ex;
}
}
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Socket.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Socket.cpp?rev=946771&r1=946770&r2=946771&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Socket.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/net/Socket.cpp Thu May 20 19:38:33 2010
@@ -139,6 +139,8 @@ void Socket::initSocketImpl( const std::
this->connected = true;
} catch( IOException& ex ) {
this->impl->close();
+ delete this->impl;
+ this->impl = NULL;
throw ex;
}
}