SESSION: internal cache sessions can't be freed same as external

refMutex is initialized for external sessions but not internal.
Differentiate by ensuring the refCount is always 1 or more for external
and 0 for internal.
This commit is contained in:
Sean Parkinson
2021-01-15 11:02:34 +10:00
parent 0ac43bb095
commit 878f797a2b

View File

@@ -21215,6 +21215,7 @@ WOLFSSL_SESSION* wolfSSL_SESSION_new(void)
XFREE(ret, NULL, DYNAMIC_TYPE_OPENSSL);
return NULL;
}
ret->refCount = 1;
}
#endif
@@ -21265,6 +21266,7 @@ WOLFSSL_SESSION* wolfSSL_SESSION_dup(WOLFSSL_SESSION* session)
XFREE(copy, NULL, DYNAMIC_TYPE_OPENSSL);
return NULL;
}
copy->refCount = 1;
#endif
#ifdef HAVE_SESSION_TICKET
if (session->isDynamic) {
@@ -21301,15 +21303,19 @@ void FreeSession(WOLFSSL_SESSION* session, int isAlloced)
#endif
#ifdef OPENSSL_EXTRA
/* refCount will always be 1 or more if created externally.
* Internal cache sessions don't initialize a refMutex. */
if (session->refCount > 0) {
if (wc_LockMutex(&session->refMutex) != 0) {
WOLFSSL_MSG("Failed to lock session mutex");
}
if (session->refCount > 0) {
if (session->refCount > 1) {
session->refCount--;
wc_UnLockMutex(&session->refMutex);
return;
}
wc_UnLockMutex(&session->refMutex);
}
#endif
#if defined(HAVE_EXT_CACHE) || defined(OPENSSL_EXTRA)
if (isAlloced) {