Merge pull request #3655 from SparkiDev/ext_cache_sess

SESSION: internal cache sessions can't be freed same as external
This commit is contained in:
toddouska
2021-01-21 15:54:16 -08:00
committed by GitHub

View File

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