Skip to content

Commit

Permalink
Public-Auto-release: v2.20.4
Browse files Browse the repository at this point in the history
# Changed
* [closes #42735, refs #41706] Bugfix: Free memory properly on failed connection in constructor
  • Loading branch information
blickfeld-lidar committed Sep 21, 2022
1 parent 1254f5a commit 9948e6f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
5 changes: 5 additions & 0 deletions doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ influence the resulting point cloud.

### Removed

## [2.20.4] - 2022.09.21

### Changed
* [closes #42735, refs #41706] Bugfix: Free memory properly on failed connection in constructor

## [2.20.3] - 2022.07.25

### Changed
Expand Down
2 changes: 2 additions & 0 deletions include/blickfeld/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class BF_DLLEXPORT scanner : public logged_object {
*/
std::shared_ptr<connection> create_connection();

void destruct();

public:
virtual ~scanner();

Expand Down
62 changes: 36 additions & 26 deletions src/scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,39 +154,49 @@ scanner::scanner(std::string hostname_or_ip, std::string cert_key_file) :
logged_object("bf::" + hostname_or_ip),
io_context(new asio::io_context()),
hostname_or_ip(hostname_or_ip) {
if (cert_key_file != "") {
#ifdef HAVE_OPENSSL
ssl_context = new asio::ssl::context(asio::ssl::context::sslv23_client);
ssl_context->set_options(asio::ssl::context::default_workarounds|asio::ssl::context::no_sslv2|asio::ssl::context::single_dh_use);
ssl_context->use_certificate_file(cert_key_file, asio::ssl::context::pem);
ssl_context->use_private_key_file(cert_key_file, asio::ssl::context::pem);
ssl_context->set_verify_mode(asio::ssl::verify_none);
ssl_context->load_verify_file(cert_key_file);
conn = new scanner_connection(*io_context, hostname_or_ip, *ssl_context);
#else
throw protocol_exception<protocol::Error::NotImplemented>();
#endif
} else {
conn = new scanner_connection(*io_context, hostname_or_ip);
}

protocol::Response::Hello _hello;
__hello(&_hello);
try {
if (cert_key_file != "") {
#ifdef HAVE_OPENSSL
ssl_context = new asio::ssl::context(asio::ssl::context::sslv23_client);
ssl_context->set_options(asio::ssl::context::default_workarounds|asio::ssl::context::no_sslv2|asio::ssl::context::single_dh_use);
ssl_context->use_certificate_file(cert_key_file, asio::ssl::context::pem);
ssl_context->use_private_key_file(cert_key_file, asio::ssl::context::pem);
ssl_context->set_verify_mode(asio::ssl::verify_none);
ssl_context->load_verify_file(cert_key_file);
conn = new scanner_connection(*io_context, hostname_or_ip, *ssl_context);
#else
throw protocol_exception<protocol::Error::NotImplemented>();
#endif
} else {
conn = new scanner_connection(*io_context, hostname_or_ip);
}

protocol::Response::Hello _hello;
__hello(&_hello);

// Compare library version of server and client
if (std::string(BSL_VERSION) != _hello.library_version()) {
auto local_version = parse_version(std::string(BSL_VERSION));
auto server_version = parse_version(_hello.library_version());
// Compare library version of server and client
if (std::string(BSL_VERSION) != _hello.library_version()) {
auto local_version = parse_version(std::string(BSL_VERSION));
auto server_version = parse_version(_hello.library_version());

// Only warn if major or minor version does not match
if (std::get<0>(local_version) != std::get<0>(server_version) || std::get<1>(local_version) != std::get<1>(server_version))
log_warning("Warning: The client BSL version does not match the server BSL version. Client has '%s', server has '%s'.\n",
BSL_VERSION,
_hello.library_version().c_str());
// Only warn if major or minor version does not match
if (std::get<0>(local_version) != std::get<0>(server_version) || std::get<1>(local_version) != std::get<1>(server_version))
log_warning("Warning: The client BSL version does not match the server BSL version. Client has '%s', server has '%s'.\n",
BSL_VERSION,
_hello.library_version().c_str());
}
} catch (const std::exception& e) {
destruct();
throw;
}
}

scanner::~scanner() {
destruct();
}

void scanner::destruct() {
if(conn)
delete conn;
#ifdef HAVE_OPENSSL
Expand Down

0 comments on commit 9948e6f

Please sign in to comment.