From 229cecfb610c93934a51fc65c6bb4a5a2aad5444 Mon Sep 17 00:00:00 2001 From: David Garske Date: Mon, 30 Oct 2017 09:49:08 -0700 Subject: [PATCH] Fix static memory failure case (insuficient mem) in InitSSL case where `ssl->ctx` isn't set yet and `SSL_ResourceFree` is called NULL dereferece happens. --- src/internal.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/internal.c b/src/internal.c index a67810fc3..22067077a 100644 --- a/src/internal.c +++ b/src/internal.c @@ -4864,9 +4864,10 @@ void SSL_ResourceFree(WOLFSSL* ssl) /* check if tracking stats */ if (ctx_heap->flag & WOLFMEM_TRACK_STATS) { - XFREE(ssl_hint->stats, ssl->heap, DYNAMIC_TYPE_SSL); + XFREE(ssl_hint->stats, ssl->ctx ? ssl->ctx->heap : NULL, + DYNAMIC_TYPE_SSL); } - XFREE(ssl->heap, ssl->heap, DYNAMIC_TYPE_SSL); + XFREE(ssl->heap, ssl->ctx ? ssl->ctx->heap : NULL, DYNAMIC_TYPE_SSL); #ifdef WOLFSSL_HEAP_TEST } #endif