diff --git a/wolfcrypt/src/aes.c b/wolfcrypt/src/aes.c index d7c12f21a2..25b7be1c15 100644 --- a/wolfcrypt/src/aes.c +++ b/wolfcrypt/src/aes.c @@ -14060,11 +14060,16 @@ static WARN_UNUSED_RESULT int AesSivCipher( } } - aes->isAllocated = 0; - wc_AesFree(aes); #ifdef WOLFSSL_SMALL_STACK - XFREE(aes, NULL, DYNAMIC_TYPE_AES); + if (aes != NULL) #endif + { + aes->isAllocated = 0; + wc_AesFree(aes); + #ifdef WOLFSSL_SMALL_STACK + XFREE(aes, NULL, DYNAMIC_TYPE_AES); + #endif + } return ret; } diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 12c6812795..dba82bcc91 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -15913,8 +15913,8 @@ static wc_test_ret_t aesccm_128_test(void) XMEMSET(p2, 0, sizeof(p2)); XMEMSET(iv2, 0, sizeof(iv2)); -#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) wc_AesFree(enc); +#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) enc = wc_AesNew(HEAP_HINT, devId); if (enc == NULL) ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), out);