Skip to content

Commit

Permalink
Ensure derived struct instances are properly destructed (apache#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
swebb2066 authored Jun 19, 2023
1 parent 64df3d4 commit 43e01bf
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
7 changes: 4 additions & 3 deletions src/main/cpp/aprsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ namespace helpers
{

struct APRSocket::APRSocketPriv : public Socket::SocketPrivate {
APRSocketPriv() :
socket(nullptr)
APRSocketPriv(InetAddressPtr& address, int port)
: Socket::SocketPrivate(address, port)
, socket(nullptr)
{}

APRSocketPriv(apr_socket_t* sock, apr_pool_t* p) :
Expand All @@ -45,7 +46,7 @@ struct APRSocket::APRSocketPriv : public Socket::SocketPrivate {
#define _priv static_cast<APRSocketPriv*>(m_priv.get())

APRSocket::APRSocket(InetAddressPtr& address, int port) :
Socket(std::make_unique<APRSocketPriv>()){
Socket(std::make_unique<APRSocketPriv>(address, port)){
apr_status_t status =
apr_socket_create(&_priv->socket, APR_INET, SOCK_STREAM,
APR_PROTO_TCP, _priv->pool.getAPRPool());
Expand Down
4 changes: 2 additions & 2 deletions src/main/cpp/datagramsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ DatagramSocketUniquePtr DatagramSocket::create(){
}

DatagramSocketUniquePtr DatagramSocket::create(int localPort1){
std::unique_ptr<APRDatagramSocket> sock = std::make_unique<APRDatagramSocket>();
auto sock = std::make_unique<APRDatagramSocket>(localPort1);
InetAddressPtr bindAddr = InetAddress::anyAddress();

sock->bind(localPort1, bindAddr);
return sock;
}

DatagramSocketUniquePtr DatagramSocket::create(int localPort1, InetAddressPtr localAddress1){
std::unique_ptr<APRDatagramSocket> sock = std::make_unique<APRDatagramSocket>();
auto sock = std::make_unique<APRDatagramSocket>(localPort1, localAddress1);

sock->bind(localPort1, localAddress1);
return sock;
Expand Down
10 changes: 6 additions & 4 deletions src/main/include/log4cxx/private/datagramsocket_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,23 @@ namespace helpers

struct DatagramSocket::DatagramSocketPriv
{
DatagramSocketPriv()
: address(), localAddress(), port(0), localPort(0)
DatagramSocketPriv()
: port(0), localPort(0)
{
}

DatagramSocketPriv(int localPort1)
: address(), localAddress(), port(0), localPort(0)
: port(0), localPort(localPort1)
{
}

DatagramSocketPriv(int localPort1, InetAddressPtr localAddress1)
: address(), localAddress(), port(0), localPort(0)
: localAddress(localAddress1), port(0), localPort(localPort1)
{
}

~DatagramSocketPriv() = default;

InetAddressPtr address;

InetAddressPtr localAddress;
Expand Down
8 changes: 4 additions & 4 deletions src/main/include/log4cxx/private/serversocket_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ namespace helpers
{

struct ServerSocket::ServerSocketPrivate{
ServerSocketPrivate() :
timeout(0){}

int timeout;
ServerSocketPrivate() :
timeout(0){}
virtual ~ServerSocketPrivate() = default;
int timeout;
};

}
Expand Down
16 changes: 10 additions & 6 deletions src/main/include/log4cxx/private/socket_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ namespace log4cxx
namespace helpers
{

struct Socket::SocketPrivate{
/** The IP address of the remote end of this socket. */
InetAddressPtr address;
struct Socket::SocketPrivate
{
SocketPrivate(const InetAddressPtr& addr = InetAddressPtr(), int _port = 0)
: address(addr), port(_port) {}
virtual ~SocketPrivate() = default;
/** The IP address of the remote end of this socket. */
InetAddressPtr address;

/** The port number on the remote host to which
this socket is connected. */
int port;
/** The port number on the remote host to which
this socket is connected. */
int port;
};

}
Expand Down

0 comments on commit 43e01bf

Please sign in to comment.