From 13bd1db1f732aa5ae2052a6d3c2c79b519886974 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Mon, 25 Feb 2019 18:36:51 -0800 Subject: [PATCH] [dtls] do not free mbedtls context if one is already being used (#3628) --- src/core/meshcop/dtls.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/meshcop/dtls.cpp b/src/core/meshcop/dtls.cpp index e3eab7dc4..30c43e773 100644 --- a/src/core/meshcop/dtls.cpp +++ b/src/core/meshcop/dtls.cpp @@ -160,6 +160,8 @@ otError Dtls::Start(bool aClient, // do not handle new connection before guard time expired VerifyOrExit(mState == kStateStopped, rval = MBEDTLS_ERR_SSL_TIMEOUT); + mState = kStateConnecting; + mbedtls_ssl_init(&mSsl); mbedtls_ssl_config_init(&mConf); mbedtls_ctr_drbg_init(&mCtrDrbg); @@ -244,7 +246,6 @@ otError Dtls::Start(bool aClient, mContext = aContext; mReceiveMessage = NULL; mMessageSubType = Message::kSubTypeNone; - mState = kStateConnecting; if (mCipherSuites[0] == MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8) { @@ -260,8 +261,9 @@ otError Dtls::Start(bool aClient, Process(); exit: - if (rval != 0) + if ((mState == kStateConnecting) && (rval != 0)) { + mState = kStateStopped; FreeMbedtls(); }