Merge pull request #2562 from JacobBarthelmeh/staticmemory

fix for memory management on edge case with staticmemory
This commit is contained in:
toddouska
2019-11-06 13:04:33 -08:00
committed by GitHub
2 changed files with 17 additions and 5 deletions

View File

@ -1470,6 +1470,7 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
#ifdef DEBUG_WOLFSSL
WOLFSSL_MEM_STATS mem_stats;
#endif
WOLFSSL_HEAP_HINT *heap = NULL;
#endif
((func_args*)args)->return_code = -1; /* error state */
@ -2162,20 +2163,24 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
WOLFMEM_IO_POOL_FIXED));
#endif /* DEBUG_WOLFSSL */
if (wolfSSL_CTX_load_static_memory(&ctx, method, memory, sizeof(memory),
0, 1) != WOLFSSL_SUCCESS) {
if (wc_LoadStaticMemory(&heap, memory, sizeof(memory), WOLFMEM_GENERAL, 1)
!= 0) {
err_sys("unable to load static memory");
}
ctx = wolfSSL_CTX_new_ex(method(heap), heap);
if (ctx == NULL)
err_sys("unable to get ctx");
if (wolfSSL_CTX_load_static_memory(&ctx, NULL, memoryIO, sizeof(memoryIO),
WOLFMEM_IO_POOL_FIXED | WOLFMEM_TRACK_STATS, 1) != WOLFSSL_SUCCESS) {
err_sys("unable to load static memory");
}
#else
ctx = wolfSSL_CTX_new(method(NULL));
#endif
if (ctx == NULL)
err_sys("unable to get ctx");
#endif
#ifdef SINGLE_THREADED
if (wolfSSL_CTX_new_rng(ctx) != WOLFSSL_SUCCESS) {

View File

@ -336,7 +336,15 @@ WOLFSSL_CTX* wolfSSL_CTX_new_ex(WOLFSSL_METHOD* method, void* heap)
ctx = (WOLFSSL_CTX*) XMALLOC(sizeof(WOLFSSL_CTX), heap, DYNAMIC_TYPE_CTX);
if (ctx) {
if (InitSSL_Ctx(ctx, method, heap) < 0) {
int ret;
ret = InitSSL_Ctx(ctx, method, heap);
#ifdef WOLFSSL_STATIC_MEMORY
if (heap != NULL) {
ctx->onHeap = 1; /* free the memory back to heap when done */
}
#endif
if (ret < 0) {
WOLFSSL_MSG("Init CTX failed");
wolfSSL_CTX_free(ctx);
ctx = NULL;
@ -1440,7 +1448,6 @@ 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 */