From 5b4bf9003e7eb12941ded5eb9196fce4e1c0fdc8 Mon Sep 17 00:00:00 2001 From: Haswell Date: Thu, 9 May 2024 18:57:51 +0800 Subject: [PATCH 1/7] solution to possible dangling pointer done --- implementation/endpoints/include/tcp_server_endpoint_impl.hpp | 2 +- .../endpoints/src/local_tcp_server_endpoint_impl.cpp | 4 ++-- implementation/endpoints/src/tcp_server_endpoint_impl.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/implementation/endpoints/include/tcp_server_endpoint_impl.hpp b/implementation/endpoints/include/tcp_server_endpoint_impl.hpp index 38834acfa..7f403f900 100644 --- a/implementation/endpoints/include/tcp_server_endpoint_impl.hpp +++ b/implementation/endpoints/include/tcp_server_endpoint_impl.hpp @@ -143,7 +143,7 @@ class tcp_server_endpoint_impl: public tcp_server_endpoint_base_impl { private: void remove_connection(connection *_connection); - void accept_cbk(const connection::ptr& _connection, + void accept_cbk(connection::ptr&& _connection, boost::system::error_code const &_error); std::string get_remote_information( const target_data_iterator_type _it) const; diff --git a/implementation/endpoints/src/local_tcp_server_endpoint_impl.cpp b/implementation/endpoints/src/local_tcp_server_endpoint_impl.cpp index e9ff0ee40..4b75ca5be 100644 --- a/implementation/endpoints/src/local_tcp_server_endpoint_impl.cpp +++ b/implementation/endpoints/src/local_tcp_server_endpoint_impl.cpp @@ -98,7 +98,7 @@ void local_tcp_server_endpoint_impl::start() { std::dynamic_pointer_cast< local_tcp_server_endpoint_impl >(shared_from_this()), - new_connection, + std::move(new_connection), std::placeholders::_1 ) ); @@ -223,7 +223,7 @@ void local_tcp_server_endpoint_impl::remove_connection( } void local_tcp_server_endpoint_impl::accept_cbk( - const connection::ptr& _connection, boost::system::error_code const &_error) { + connection::ptr&& _connection, boost::system::error_code const &_error) { if (_error != boost::asio::error::bad_descriptor && _error != boost::asio::error::operation_aborted && _error != boost::asio::error::no_descriptors) { diff --git a/implementation/endpoints/src/tcp_server_endpoint_impl.cpp b/implementation/endpoints/src/tcp_server_endpoint_impl.cpp index 5aef72be9..027ddf89f 100644 --- a/implementation/endpoints/src/tcp_server_endpoint_impl.cpp +++ b/implementation/endpoints/src/tcp_server_endpoint_impl.cpp @@ -93,7 +93,7 @@ void tcp_server_endpoint_impl::start() { acceptor_.async_accept(new_connection->get_socket(), std::bind(&tcp_server_endpoint_impl::accept_cbk, std::dynamic_pointer_cast( - shared_from_this()), new_connection, + shared_from_this()), std::move(new_connection), std::placeholders::_1)); } } @@ -253,7 +253,7 @@ void tcp_server_endpoint_impl::remove_connection( } } -void tcp_server_endpoint_impl::accept_cbk(const connection::ptr& _connection, +void tcp_server_endpoint_impl::accept_cbk(connection::ptr&& _connection, boost::system::error_code const &_error) { if (!_error) { From 76eb9c9f8425db18382712f333ab8a9dae7240ee Mon Sep 17 00:00:00 2001 From: Haswell Date: Thu, 9 May 2024 19:03:51 +0800 Subject: [PATCH 2/7] solution to possible dangling pointer done --- .../endpoints/include/local_tcp_server_endpoint_impl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/implementation/endpoints/include/local_tcp_server_endpoint_impl.hpp b/implementation/endpoints/include/local_tcp_server_endpoint_impl.hpp index 49b6fcb77..7d5260d83 100644 --- a/implementation/endpoints/include/local_tcp_server_endpoint_impl.hpp +++ b/implementation/endpoints/include/local_tcp_server_endpoint_impl.hpp @@ -152,7 +152,7 @@ class local_tcp_server_endpoint_impl bool add_connection(const client_t &_client, const std::shared_ptr &_connection); void remove_connection(const client_t &_client); - void accept_cbk(const connection::ptr& _connection, + void accept_cbk(connection::ptr&& _connection, boost::system::error_code const &_error); std::string get_remote_information( const target_data_iterator_type _queue_iterator) const; From cfdaa6ed4108cba5cb613b178ec2f45128923e5a Mon Sep 17 00:00:00 2001 From: Haswell Date: Thu, 9 May 2024 19:10:08 +0800 Subject: [PATCH 3/7] solution to possible dangling pointer done --- .../endpoints/include/local_tcp_server_endpoint_impl.hpp | 2 +- implementation/endpoints/include/tcp_server_endpoint_impl.hpp | 2 +- implementation/endpoints/src/local_tcp_server_endpoint_impl.cpp | 2 +- implementation/endpoints/src/tcp_server_endpoint_impl.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/implementation/endpoints/include/local_tcp_server_endpoint_impl.hpp b/implementation/endpoints/include/local_tcp_server_endpoint_impl.hpp index 7d5260d83..25cda5c05 100644 --- a/implementation/endpoints/include/local_tcp_server_endpoint_impl.hpp +++ b/implementation/endpoints/include/local_tcp_server_endpoint_impl.hpp @@ -152,7 +152,7 @@ class local_tcp_server_endpoint_impl bool add_connection(const client_t &_client, const std::shared_ptr &_connection); void remove_connection(const client_t &_client); - void accept_cbk(connection::ptr&& _connection, + void accept_cbk(const connection::ptr&& _connection, boost::system::error_code const &_error); std::string get_remote_information( const target_data_iterator_type _queue_iterator) const; diff --git a/implementation/endpoints/include/tcp_server_endpoint_impl.hpp b/implementation/endpoints/include/tcp_server_endpoint_impl.hpp index 7f403f900..1f3a11c8c 100644 --- a/implementation/endpoints/include/tcp_server_endpoint_impl.hpp +++ b/implementation/endpoints/include/tcp_server_endpoint_impl.hpp @@ -143,7 +143,7 @@ class tcp_server_endpoint_impl: public tcp_server_endpoint_base_impl { private: void remove_connection(connection *_connection); - void accept_cbk(connection::ptr&& _connection, + void accept_cbk(const connection::ptr&& _connection, boost::system::error_code const &_error); std::string get_remote_information( const target_data_iterator_type _it) const; diff --git a/implementation/endpoints/src/local_tcp_server_endpoint_impl.cpp b/implementation/endpoints/src/local_tcp_server_endpoint_impl.cpp index 4b75ca5be..abdc46357 100644 --- a/implementation/endpoints/src/local_tcp_server_endpoint_impl.cpp +++ b/implementation/endpoints/src/local_tcp_server_endpoint_impl.cpp @@ -223,7 +223,7 @@ void local_tcp_server_endpoint_impl::remove_connection( } void local_tcp_server_endpoint_impl::accept_cbk( - connection::ptr&& _connection, boost::system::error_code const &_error) { + const connection::ptr&& _connection, boost::system::error_code const &_error) { if (_error != boost::asio::error::bad_descriptor && _error != boost::asio::error::operation_aborted && _error != boost::asio::error::no_descriptors) { diff --git a/implementation/endpoints/src/tcp_server_endpoint_impl.cpp b/implementation/endpoints/src/tcp_server_endpoint_impl.cpp index 027ddf89f..fdcba39f9 100644 --- a/implementation/endpoints/src/tcp_server_endpoint_impl.cpp +++ b/implementation/endpoints/src/tcp_server_endpoint_impl.cpp @@ -253,7 +253,7 @@ void tcp_server_endpoint_impl::remove_connection( } } -void tcp_server_endpoint_impl::accept_cbk(connection::ptr&& _connection, +void tcp_server_endpoint_impl::accept_cbk(const connection::ptr&& _connection, boost::system::error_code const &_error) { if (!_error) { From bf14841b2eff26ba710a20482b3911d5fb8fe482 Mon Sep 17 00:00:00 2001 From: Haswell Date: Thu, 9 May 2024 19:59:50 +0800 Subject: [PATCH 4/7] std::bind will cause rvalue reference not usable, simply accept a copy as parameter --- .../endpoints/include/local_tcp_server_endpoint_impl.hpp | 2 +- implementation/endpoints/include/tcp_server_endpoint_impl.hpp | 2 +- .../endpoints/src/local_tcp_server_endpoint_impl.cpp | 4 ++-- implementation/endpoints/src/tcp_server_endpoint_impl.cpp | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/implementation/endpoints/include/local_tcp_server_endpoint_impl.hpp b/implementation/endpoints/include/local_tcp_server_endpoint_impl.hpp index 25cda5c05..a51783f68 100644 --- a/implementation/endpoints/include/local_tcp_server_endpoint_impl.hpp +++ b/implementation/endpoints/include/local_tcp_server_endpoint_impl.hpp @@ -152,7 +152,7 @@ class local_tcp_server_endpoint_impl bool add_connection(const client_t &_client, const std::shared_ptr &_connection); void remove_connection(const client_t &_client); - void accept_cbk(const connection::ptr&& _connection, + void accept_cbk(connection::ptr _connection, boost::system::error_code const &_error); std::string get_remote_information( const target_data_iterator_type _queue_iterator) const; diff --git a/implementation/endpoints/include/tcp_server_endpoint_impl.hpp b/implementation/endpoints/include/tcp_server_endpoint_impl.hpp index 1f3a11c8c..9900e9354 100644 --- a/implementation/endpoints/include/tcp_server_endpoint_impl.hpp +++ b/implementation/endpoints/include/tcp_server_endpoint_impl.hpp @@ -143,7 +143,7 @@ class tcp_server_endpoint_impl: public tcp_server_endpoint_base_impl { private: void remove_connection(connection *_connection); - void accept_cbk(const connection::ptr&& _connection, + void accept_cbk(connection::ptr _connection, boost::system::error_code const &_error); std::string get_remote_information( const target_data_iterator_type _it) const; diff --git a/implementation/endpoints/src/local_tcp_server_endpoint_impl.cpp b/implementation/endpoints/src/local_tcp_server_endpoint_impl.cpp index abdc46357..8a7de444d 100644 --- a/implementation/endpoints/src/local_tcp_server_endpoint_impl.cpp +++ b/implementation/endpoints/src/local_tcp_server_endpoint_impl.cpp @@ -98,7 +98,7 @@ void local_tcp_server_endpoint_impl::start() { std::dynamic_pointer_cast< local_tcp_server_endpoint_impl >(shared_from_this()), - std::move(new_connection), + new_connection, std::placeholders::_1 ) ); @@ -223,7 +223,7 @@ void local_tcp_server_endpoint_impl::remove_connection( } void local_tcp_server_endpoint_impl::accept_cbk( - const connection::ptr&& _connection, boost::system::error_code const &_error) { + connection::ptr _connection, boost::system::error_code const &_error) { if (_error != boost::asio::error::bad_descriptor && _error != boost::asio::error::operation_aborted && _error != boost::asio::error::no_descriptors) { diff --git a/implementation/endpoints/src/tcp_server_endpoint_impl.cpp b/implementation/endpoints/src/tcp_server_endpoint_impl.cpp index fdcba39f9..30bfba1dc 100644 --- a/implementation/endpoints/src/tcp_server_endpoint_impl.cpp +++ b/implementation/endpoints/src/tcp_server_endpoint_impl.cpp @@ -93,7 +93,7 @@ void tcp_server_endpoint_impl::start() { acceptor_.async_accept(new_connection->get_socket(), std::bind(&tcp_server_endpoint_impl::accept_cbk, std::dynamic_pointer_cast( - shared_from_this()), std::move(new_connection), + shared_from_this()), new_connection std::placeholders::_1)); } } @@ -253,7 +253,7 @@ void tcp_server_endpoint_impl::remove_connection( } } -void tcp_server_endpoint_impl::accept_cbk(const connection::ptr&& _connection, +void tcp_server_endpoint_impl::accept_cbk(connection::ptr_connection, boost::system::error_code const &_error) { if (!_error) { From 58e58471e5df24c29130847ad16ae1b482980d96 Mon Sep 17 00:00:00 2001 From: Haswell Date: Thu, 9 May 2024 20:02:22 +0800 Subject: [PATCH 5/7] std::bind will cause rvalue reference not usable, simply accept a copy as parameter --- implementation/endpoints/src/tcp_server_endpoint_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/implementation/endpoints/src/tcp_server_endpoint_impl.cpp b/implementation/endpoints/src/tcp_server_endpoint_impl.cpp index 30bfba1dc..a3ac10bae 100644 --- a/implementation/endpoints/src/tcp_server_endpoint_impl.cpp +++ b/implementation/endpoints/src/tcp_server_endpoint_impl.cpp @@ -93,7 +93,7 @@ void tcp_server_endpoint_impl::start() { acceptor_.async_accept(new_connection->get_socket(), std::bind(&tcp_server_endpoint_impl::accept_cbk, std::dynamic_pointer_cast( - shared_from_this()), new_connection + shared_from_this()), new_connection, std::placeholders::_1)); } } From c654804e9cd7fa854dbea4871601193f9dfc221b Mon Sep 17 00:00:00 2001 From: Haswell Date: Thu, 9 May 2024 20:06:10 +0800 Subject: [PATCH 6/7] std::bind will cause rvalue reference not usable, simply accept a copy as parameter --- implementation/endpoints/src/tcp_server_endpoint_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/implementation/endpoints/src/tcp_server_endpoint_impl.cpp b/implementation/endpoints/src/tcp_server_endpoint_impl.cpp index a3ac10bae..079eeea4b 100644 --- a/implementation/endpoints/src/tcp_server_endpoint_impl.cpp +++ b/implementation/endpoints/src/tcp_server_endpoint_impl.cpp @@ -253,7 +253,7 @@ void tcp_server_endpoint_impl::remove_connection( } } -void tcp_server_endpoint_impl::accept_cbk(connection::ptr_connection, +void tcp_server_endpoint_impl::accept_cbk(connection::ptr _connection, boost::system::error_code const &_error) { if (!_error) { From 04f3ce9410fe73deea53a6c4412345d6ebfbc338 Mon Sep 17 00:00:00 2001 From: Lutz Bichler Date: Fri, 18 Oct 2024 11:56:50 +0200 Subject: [PATCH 7/7] Adapt signatures to fix compilation --- .../endpoints/include/local_uds_server_endpoint_impl.hpp | 2 +- implementation/endpoints/src/local_uds_server_endpoint_impl.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/implementation/endpoints/include/local_uds_server_endpoint_impl.hpp b/implementation/endpoints/include/local_uds_server_endpoint_impl.hpp index a0d8bde1e..94c39bb7e 100644 --- a/implementation/endpoints/include/local_uds_server_endpoint_impl.hpp +++ b/implementation/endpoints/include/local_uds_server_endpoint_impl.hpp @@ -156,7 +156,7 @@ class local_uds_server_endpoint_impl: public local_uds_server_endpoint_base_impl bool add_connection(const client_t &_client, const std::shared_ptr &_connection); void remove_connection(const client_t &_client); - void accept_cbk(const connection::ptr& _connection, + void accept_cbk(connection::ptr _connection, boost::system::error_code const &_error); std::string get_remote_information( const target_data_iterator_type _queue_iterator) const; diff --git a/implementation/endpoints/src/local_uds_server_endpoint_impl.cpp b/implementation/endpoints/src/local_uds_server_endpoint_impl.cpp index 2717a6869..5b8560bdc 100644 --- a/implementation/endpoints/src/local_uds_server_endpoint_impl.cpp +++ b/implementation/endpoints/src/local_uds_server_endpoint_impl.cpp @@ -242,7 +242,7 @@ void local_uds_server_endpoint_impl::remove_connection( } void local_uds_server_endpoint_impl::accept_cbk( - const connection::ptr& _connection, boost::system::error_code const &_error) { + connection::ptr _connection, boost::system::error_code const &_error) { if (_error != boost::asio::error::bad_descriptor && _error != boost::asio::error::operation_aborted && _error != boost::asio::error::no_descriptors) {