From 7533b1d93afc38f7b244d87dc6b0f59679c1999b Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Tue, 3 Jun 2025 22:34:22 -0700 Subject: [PATCH] [secure-transport] add `~SecureTransport()` destructor (#11562) This commit adds a destructor for `SecureTransport` that closes the socket, and disconnects and removes any tracked sessions. Removing the sessions ensures that the `SecureSession` instances and any data allocated within them are properly freed. This handles the case where the `otInstance` itself is destroyed, ensuring that all heap-allocated items are cleaned up correctly to prevent memory leaks. --- src/core/meshcop/secure_transport.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/meshcop/secure_transport.hpp b/src/core/meshcop/secure_transport.hpp index f5ffd0d67..a39dad990 100644 --- a/src/core/meshcop/secure_transport.hpp +++ b/src/core/meshcop/secure_transport.hpp @@ -721,6 +721,7 @@ public: protected: SecureTransport(Instance &aInstance, LinkSecurityMode aLayerTwoSecurity, bool aDatagramTransport); + ~SecureTransport(void) { Close(); } #if OPENTHREAD_CONFIG_TLS_API_ENABLE void SetExtension(Extension &aExtension) { mExtension = &aExtension; }