From 7bb2a69161bfb2464f4482cd8a60ae0495c557a5 Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Mon, 10 Aug 2020 12:42:46 +1000 Subject: [PATCH] Fix memory leak in api.c When testing wc_ecc_import_raw(), the mp_int's in the ecc object are initialized. For small math, this throws away the allocated buffer. Must free the object before importing. --- tests/api.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/api.c b/tests/api.c index fedaf2c55..ef0f1912d 100644 --- a/tests/api.c +++ b/tests/api.c @@ -19602,6 +19602,9 @@ static int test_wc_ecc_import_raw(void) } #ifdef WOLFSSL_VALIDATE_ECC_IMPORT if (ret == BAD_FUNC_ARG) { + #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH) + wc_ecc_free(&key); + #endif ret = wc_ecc_import_raw(&key, kNullStr, kNullStr, kNullStr, curveName); if (ret == ECC_INF_E) ret = BAD_FUNC_ARG; /* This is expected by other tests */ @@ -19609,9 +19612,15 @@ static int test_wc_ecc_import_raw(void) #endif #if !defined(HAVE_SELFTEST) && !defined(HAVE_FIPS) if (ret == BAD_FUNC_ARG) { + #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH) + wc_ecc_free(&key); + #endif ret = wc_ecc_import_raw(&key, "0", qy, d, curveName); } if (ret == BAD_FUNC_ARG) { + #if !defined(USE_FAST_MATH) && !defined(WOLFSSL_SP_MATH) + wc_ecc_free(&key); + #endif ret = wc_ecc_import_raw(&key, qx, "0", d, curveName); } #endif