You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by sw...@apache.org on 2023/06/18 04:25:02 UTC
[logging-log4cxx] 01/01: Ensure derived struct instances are properly destructed
This is an automated email from the ASF dual-hosted git repository.
swebb2066 pushed a commit to branch prevent_new_delete_type_mismatch
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
commit 046aead745b44c0482115c8f6c838b4401c93cb8
Author: Stephen Webb <sw...@gmail.com>
AuthorDate: Sun Jun 18 14:23:58 2023 +1000
Ensure derived struct instances are properly destructed
---
src/main/cpp/aprsocket.cpp | 7 ++++---
src/main/cpp/datagramsocket.cpp | 4 ++--
src/main/include/log4cxx/private/datagramsocket_priv.h | 10 ++++++----
src/main/include/log4cxx/private/serversocket_priv.h | 8 ++++----
src/main/include/log4cxx/private/socket_priv.h | 16 ++++++++++------
5 files changed, 26 insertions(+), 19 deletions(-)
diff --git a/src/main/cpp/aprsocket.cpp b/src/main/cpp/aprsocket.cpp
index 624363aa..fb7a233c 100644
--- a/src/main/cpp/aprsocket.cpp
+++ b/src/main/cpp/aprsocket.cpp
@@ -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) :
@@ -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());
diff --git a/src/main/cpp/datagramsocket.cpp b/src/main/cpp/datagramsocket.cpp
index ac71ecbe..7741eb34 100644
--- a/src/main/cpp/datagramsocket.cpp
+++ b/src/main/cpp/datagramsocket.cpp
@@ -84,7 +84,7 @@ 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);
@@ -92,7 +92,7 @@ DatagramSocketUniquePtr DatagramSocket::create(int localPort1){
}
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;
diff --git a/src/main/include/log4cxx/private/datagramsocket_priv.h b/src/main/include/log4cxx/private/datagramsocket_priv.h
index 1b4b4bb9..06af5714 100644
--- a/src/main/include/log4cxx/private/datagramsocket_priv.h
+++ b/src/main/include/log4cxx/private/datagramsocket_priv.h
@@ -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;
diff --git a/src/main/include/log4cxx/private/serversocket_priv.h b/src/main/include/log4cxx/private/serversocket_priv.h
index 0d3b021d..b49758c8 100644
--- a/src/main/include/log4cxx/private/serversocket_priv.h
+++ b/src/main/include/log4cxx/private/serversocket_priv.h
@@ -26,10 +26,10 @@ namespace helpers
{
struct ServerSocket::ServerSocketPrivate{
- ServerSocketPrivate() :
- timeout(0){}
-
- int timeout;
+ ServerSocketPrivate() :
+ timeout(0){}
+ ~ServerSocketPrivate() = default;
+ int timeout;
};
}
diff --git a/src/main/include/log4cxx/private/socket_priv.h b/src/main/include/log4cxx/private/socket_priv.h
index fcc09bf7..fe9a1cb6 100644
--- a/src/main/include/log4cxx/private/socket_priv.h
+++ b/src/main/include/log4cxx/private/socket_priv.h
@@ -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;
};
}