From f92108c0f3c95f6f90634b3342bee4dc10254d47 Mon Sep 17 00:00:00 2001 From: Seppo Takalo Date: Thu, 1 Nov 2018 15:30:27 +0200 Subject: [PATCH] Make sure that close() is called before the transport is destroyed. Transport is a member of TLSSocket which is derived from TLSSocketWrapper. Make sure that TLSSocketWrapper::close() is called before the transport is destroyed. --- features/netsocket/TLSSocket.cpp | 9 +++++++++ features/netsocket/TLSSocket.h | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/features/netsocket/TLSSocket.cpp b/features/netsocket/TLSSocket.cpp index 56583aaf42..bf53be6d2c 100644 --- a/features/netsocket/TLSSocket.cpp +++ b/features/netsocket/TLSSocket.cpp @@ -35,4 +35,13 @@ nsapi_error_t TLSSocket::connect(const char *host, uint16_t port) return TLSSocketWrapper::do_handshake(); } +TLSSocket::~TLSSocket() +{ + /* Transport is a member of TLSSocket which is derived from TLSSocketWrapper. + * Make sure that TLSSocketWrapper::close() is called before the transport is + * destroyed. + */ + close(); +} + #endif // MBEDTLS_SSL_CLI_C \ No newline at end of file diff --git a/features/netsocket/TLSSocket.h b/features/netsocket/TLSSocket.h index cbb6bb0690..13ccd787d4 100644 --- a/features/netsocket/TLSSocket.h +++ b/features/netsocket/TLSSocket.h @@ -41,6 +41,10 @@ public: */ TLSSocket() : TLSSocketWrapper(&tcp_socket) {} + /** Destroy the TLSSocket and closes the transport. + */ + virtual ~TLSSocket(); + /** Create a socket on a network interface * * Creates and opens a socket on the network stack of the given