Merge pull request #2495 from JacobBarthelmeh/staticmemory

check on if free'ing ctx/method back to heap hint
This commit is contained in:
David Garske
2019-10-07 08:10:05 -07:00
committed by GitHub
3 changed files with 21 additions and 1 deletions

View File

@ -1796,7 +1796,16 @@ void SSL_CtxResourceFree(WOLFSSL_CTX* ctx)
wolfEventQueue_Free(&ctx->event_queue);
#endif /* HAVE_WOLF_EVENT */
#ifdef WOLFSSL_STATIC_MEMORY
if (ctx->onHeap == 1) {
XFREE(ctx->method, ctx->heap, DYNAMIC_TYPE_METHOD);
}
else {
XFREE(ctx->method, NULL, DYNAMIC_TYPE_METHOD);
}
#else
XFREE(ctx->method, ctx->heap, DYNAMIC_TYPE_METHOD);
#endif
ctx->method = NULL;
if (ctx->suites) {
XFREE(ctx->suites, ctx->heap, DYNAMIC_TYPE_SUITES);
@ -1920,10 +1929,17 @@ void FreeSSL_Ctx(WOLFSSL_CTX* ctx)
wc_UnLockMutex(&ctx->countMutex);
if (doFree) {
void* heap = ctx->heap;
WOLFSSL_MSG("CTX ref count down to 0, doing full free");
SSL_CtxResourceFree(ctx);
wc_FreeMutex(&ctx->countMutex);
XFREE(ctx, ctx->heap, DYNAMIC_TYPE_CTX);
#ifdef WOLFSSL_STATIC_MEMORY
if (ctx->onHeap == 0) {
heap = NULL;
}
#endif
XFREE(ctx, heap, DYNAMIC_TYPE_CTX);
(void)heap; /* not used in some builds */
}
else {
(void)ctx;

View File

@ -1398,6 +1398,7 @@ int wolfSSL_CTX_load_static_memory(WOLFSSL_CTX** ctx, wolfSSL_method_func method
WOLFSSL_MSG("Error creating ctx");
return WOLFSSL_FAILURE;
}
(*ctx)->onHeap = 1; /* free the memory back to heap when done */
}
/* determine what max applies too */

View File

@ -2617,6 +2617,9 @@ struct WOLFSSL_CTX {
#ifdef HAVE_ENCRYPT_THEN_MAC
byte disallowEncThenMac:1; /* Don't do Encrypt-Then-MAC */
#endif
#ifdef WOLFSSL_STATIC_MEMORY
byte onHeap:1; /* whether the ctx/method is put on heap hint */
#endif
#ifdef WOLFSSL_MULTICAST
byte haveMcast; /* multicast requested */
byte mcastID; /* multicast group ID */