[dtls] do not free mbedtls context if one is already being used (#3628)

This commit is contained in:
Jonathan Hui
2019-02-25 18:36:51 -08:00
committed by GitHub
parent a3548df579
commit 13bd1db1f7
+4 -2
View File
@@ -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();
}