mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-02 04:04:39 +02:00
Fixes for static memory with -r
session resumption option on client. Fix for possible failed InitSSL cleanup using NULL ssl->ctx for static memory.
This commit is contained in:
@@ -762,17 +762,6 @@ static void Usage(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WOLFSSL_STATIC_MEMORY
|
|
||||||
#if (defined(HAVE_ECC) && !defined(ALT_ECC_SIZE)) \
|
|
||||||
|| defined(SESSION_CERTS)
|
|
||||||
/* big enough to handle most cases including session certs */
|
|
||||||
byte memory[204000];
|
|
||||||
#else
|
|
||||||
byte memory[80000];
|
|
||||||
#endif
|
|
||||||
byte memoryIO[34500]; /* max of 17k for IO buffer (TLS packet can be 16k) */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
|
THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
|
||||||
{
|
{
|
||||||
SOCKET_T sockfd = WOLFSSL_SOCKET_INVALID;
|
SOCKET_T sockfd = WOLFSSL_SOCKET_INVALID;
|
||||||
@@ -895,6 +884,22 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
|
|||||||
int argc = ((func_args*)args)->argc;
|
int argc = ((func_args*)args)->argc;
|
||||||
char** argv = ((func_args*)args)->argv;
|
char** argv = ((func_args*)args)->argv;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_STATIC_MEMORY
|
||||||
|
#if (defined(HAVE_ECC) && !defined(ALT_ECC_SIZE)) \
|
||||||
|
|| defined(SESSION_CERTS)
|
||||||
|
/* big enough to handle most cases including session certs */
|
||||||
|
byte memory[204000];
|
||||||
|
#else
|
||||||
|
byte memory[80000];
|
||||||
|
#endif
|
||||||
|
byte memoryIO[34500]; /* max for IO buffer (TLS packet can be 16k) */
|
||||||
|
WOLFSSL_MEM_CONN_STATS ssl_stats;
|
||||||
|
#ifdef DEBUG_WOLFSSL
|
||||||
|
WOLFSSL_MEM_STATS mem_stats;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
((func_args*)args)->return_code = -1; /* error state */
|
((func_args*)args)->return_code = -1; /* error state */
|
||||||
|
|
||||||
#ifdef NO_RSA
|
#ifdef NO_RSA
|
||||||
@@ -1744,14 +1749,11 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(WOLFSSL_STATIC_MEMORY) && defined(DEBUG_WOLFSSL)
|
#if defined(WOLFSSL_STATIC_MEMORY) && defined(DEBUG_WOLFSSL)
|
||||||
{
|
|
||||||
WOLFSSL_MEM_STATS mem_stats;
|
|
||||||
fprintf(stderr, "Before creating SSL\n");
|
fprintf(stderr, "Before creating SSL\n");
|
||||||
if (wolfSSL_CTX_is_static_memory(ctx, &mem_stats) != 1)
|
if (wolfSSL_CTX_is_static_memory(ctx, &mem_stats) != 1)
|
||||||
err_sys("ctx not using static memory");
|
err_sys("ctx not using static memory");
|
||||||
if (wolfSSL_PrintStats(&mem_stats) != 1) /* function in test.h */
|
if (wolfSSL_PrintStats(&mem_stats) != 1) /* function in test.h */
|
||||||
err_sys("error printing out memory stats");
|
err_sys("error printing out memory stats");
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (doMcast) {
|
if (doMcast) {
|
||||||
@@ -1776,14 +1778,11 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(WOLFSSL_STATIC_MEMORY) && defined(DEBUG_WOLFSSL)
|
#if defined(WOLFSSL_STATIC_MEMORY) && defined(DEBUG_WOLFSSL)
|
||||||
{
|
|
||||||
WOLFSSL_MEM_STATS mem_stats;
|
|
||||||
fprintf(stderr, "After creating SSL\n");
|
fprintf(stderr, "After creating SSL\n");
|
||||||
if (wolfSSL_CTX_is_static_memory(ctx, &mem_stats) != 1)
|
if (wolfSSL_CTX_is_static_memory(ctx, &mem_stats) != 1)
|
||||||
err_sys("ctx not using static memory");
|
err_sys("ctx not using static memory");
|
||||||
if (wolfSSL_PrintStats(&mem_stats) != 1) /* function in test.h */
|
if (wolfSSL_PrintStats(&mem_stats) != 1) /* function in test.h */
|
||||||
err_sys("error printing out memory stats");
|
err_sys("error printing out memory stats");
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WOLFSSL_TLS13
|
#ifdef WOLFSSL_TLS13
|
||||||
@@ -2127,12 +2126,6 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
|
|||||||
#ifndef NO_SESSION_CACHE
|
#ifndef NO_SESSION_CACHE
|
||||||
if (resumeSession) {
|
if (resumeSession) {
|
||||||
session = wolfSSL_get_session(ssl);
|
session = wolfSSL_get_session(ssl);
|
||||||
sslResume = wolfSSL_new(ctx);
|
|
||||||
if (sslResume == NULL) {
|
|
||||||
wolfSSL_free(ssl);
|
|
||||||
wolfSSL_CTX_free(ctx);
|
|
||||||
err_sys("unable to get SSL object");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -2146,11 +2139,8 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
|
|||||||
FreeAtomicUser(ssl);
|
FreeAtomicUser(ssl);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* display collected statistics */
|
/* display collected statistics */
|
||||||
#ifdef WOLFSSL_STATIC_MEMORY
|
#ifdef WOLFSSL_STATIC_MEMORY
|
||||||
{
|
|
||||||
WOLFSSL_MEM_CONN_STATS ssl_stats;
|
|
||||||
if (wolfSSL_is_static_memory(ssl, &ssl_stats) != 1)
|
if (wolfSSL_is_static_memory(ssl, &ssl_stats) != 1)
|
||||||
err_sys("static memory was not used with ssl");
|
err_sys("static memory was not used with ssl");
|
||||||
|
|
||||||
@@ -2162,7 +2152,6 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
|
|||||||
fprintf(stderr, "current connection allocs = %d\n", ssl_stats.curAlloc);
|
fprintf(stderr, "current connection allocs = %d\n", ssl_stats.curAlloc);
|
||||||
fprintf(stderr, "total connection allocs = %d\n", ssl_stats.totalAlloc);
|
fprintf(stderr, "total connection allocs = %d\n", ssl_stats.totalAlloc);
|
||||||
fprintf(stderr, "total connection frees = %d\n\n", ssl_stats.totalFr);
|
fprintf(stderr, "total connection frees = %d\n\n", ssl_stats.totalFr);
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wolfSSL_free(ssl);
|
wolfSSL_free(ssl);
|
||||||
@@ -2170,6 +2159,12 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
|
|||||||
|
|
||||||
#ifndef NO_SESSION_CACHE
|
#ifndef NO_SESSION_CACHE
|
||||||
if (resumeSession) {
|
if (resumeSession) {
|
||||||
|
sslResume = wolfSSL_new(ctx);
|
||||||
|
if (sslResume == NULL) {
|
||||||
|
wolfSSL_CTX_free(ctx);
|
||||||
|
err_sys("unable to get SSL object");
|
||||||
|
}
|
||||||
|
|
||||||
if (dtlsUDP) {
|
if (dtlsUDP) {
|
||||||
#ifdef USE_WINDOWS_API
|
#ifdef USE_WINDOWS_API
|
||||||
Sleep(500);
|
Sleep(500);
|
||||||
@@ -2459,6 +2454,21 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
|
|||||||
if (wc_shutdown && ret == WOLFSSL_SHUTDOWN_NOT_DONE)
|
if (wc_shutdown && ret == WOLFSSL_SHUTDOWN_NOT_DONE)
|
||||||
wolfSSL_shutdown(sslResume); /* bidirectional shutdown */
|
wolfSSL_shutdown(sslResume); /* bidirectional shutdown */
|
||||||
|
|
||||||
|
/* display collected statistics */
|
||||||
|
#ifdef WOLFSSL_STATIC_MEMORY
|
||||||
|
if (wolfSSL_is_static_memory(sslResume, &ssl_stats) != 1)
|
||||||
|
err_sys("static memory was not used with ssl");
|
||||||
|
|
||||||
|
fprintf(stderr, "\nprint off SSLresume memory stats\n");
|
||||||
|
fprintf(stderr, "*** This is memory state before wolfSSL_free is called\n");
|
||||||
|
fprintf(stderr, "peak connection memory = %d\n", ssl_stats.peakMem);
|
||||||
|
fprintf(stderr, "current memory in use = %d\n", ssl_stats.curMem);
|
||||||
|
fprintf(stderr, "peak connection allocs = %d\n", ssl_stats.peakAlloc);
|
||||||
|
fprintf(stderr, "current connection allocs = %d\n", ssl_stats.curAlloc);
|
||||||
|
fprintf(stderr, "total connection allocs = %d\n", ssl_stats.totalAlloc);
|
||||||
|
fprintf(stderr, "total connection frees = %d\n\n", ssl_stats.totalFr);
|
||||||
|
#endif
|
||||||
|
|
||||||
wolfSSL_free(sslResume);
|
wolfSSL_free(sslResume);
|
||||||
CloseSocket(sockfd);
|
CloseSocket(sockfd);
|
||||||
}
|
}
|
||||||
|
@@ -534,8 +534,11 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
|
|||||||
#else
|
#else
|
||||||
byte memory[80000];
|
byte memory[80000];
|
||||||
#endif
|
#endif
|
||||||
byte memoryIO[34500]; /* max of 17k for IO buffer (TLS packet can be 16k) */
|
byte memoryIO[34500]; /* max for IO buffer (TLS packet can be 16k) */
|
||||||
WOLFSSL_MEM_CONN_STATS ssl_stats;
|
WOLFSSL_MEM_CONN_STATS ssl_stats;
|
||||||
|
#ifdef DEBUG_WOLFSSL
|
||||||
|
WOLFSSL_MEM_STATS mem_stats;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
((func_args*)args)->return_code = -1; /* error state */
|
((func_args*)args)->return_code = -1; /* error state */
|
||||||
@@ -1153,14 +1156,11 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if defined(WOLFSSL_STATIC_MEMORY) && defined(DEBUG_WOLFSSL)
|
#if defined(WOLFSSL_STATIC_MEMORY) && defined(DEBUG_WOLFSSL)
|
||||||
{
|
|
||||||
WOLFSSL_MEM_STATS mem_stats;
|
|
||||||
fprintf(stderr, "Before creating SSL\n");
|
fprintf(stderr, "Before creating SSL\n");
|
||||||
if (wolfSSL_CTX_is_static_memory(ctx, &mem_stats) != 1)
|
if (wolfSSL_CTX_is_static_memory(ctx, &mem_stats) != 1)
|
||||||
err_sys_ex(runWithErrors, "ctx not using static memory");
|
err_sys_ex(runWithErrors, "ctx not using static memory");
|
||||||
if (wolfSSL_PrintStats(&mem_stats) != 1) /* function in test.h */
|
if (wolfSSL_PrintStats(&mem_stats) != 1) /* function in test.h */
|
||||||
err_sys_ex(runWithErrors, "error printing out memory stats");
|
err_sys_ex(runWithErrors, "error printing out memory stats");
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (doMcast) {
|
if (doMcast) {
|
||||||
@@ -1185,14 +1185,11 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(WOLFSSL_STATIC_MEMORY) && defined(DEBUG_WOLFSSL)
|
#if defined(WOLFSSL_STATIC_MEMORY) && defined(DEBUG_WOLFSSL)
|
||||||
{
|
|
||||||
WOLFSSL_MEM_STATS mem_stats;
|
|
||||||
fprintf(stderr, "After creating SSL\n");
|
fprintf(stderr, "After creating SSL\n");
|
||||||
if (wolfSSL_CTX_is_static_memory(ctx, &mem_stats) != 1)
|
if (wolfSSL_CTX_is_static_memory(ctx, &mem_stats) != 1)
|
||||||
err_sys_ex(runWithErrors, "ctx not using static memory");
|
err_sys_ex(runWithErrors, "ctx not using static memory");
|
||||||
if (wolfSSL_PrintStats(&mem_stats) != 1) /* function in test.h */
|
if (wolfSSL_PrintStats(&mem_stats) != 1) /* function in test.h */
|
||||||
err_sys_ex(runWithErrors, "error printing out memory stats");
|
err_sys_ex(runWithErrors, "error printing out memory stats");
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (doMcast) {
|
if (doMcast) {
|
||||||
|
@@ -71,7 +71,7 @@ do_test() {
|
|||||||
|
|
||||||
if [ $client_result != 0 ]
|
if [ $client_result != 0 ]
|
||||||
then
|
then
|
||||||
echo -e "client failed!"
|
echo -e "client failed!\ncapture_out=$capture_out\nclient_result=$client_result"
|
||||||
do_cleanup
|
do_cleanup
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@@ -4864,9 +4864,9 @@ void SSL_ResourceFree(WOLFSSL* ssl)
|
|||||||
|
|
||||||
/* check if tracking stats */
|
/* check if tracking stats */
|
||||||
if (ctx_heap->flag & WOLFMEM_TRACK_STATS) {
|
if (ctx_heap->flag & WOLFMEM_TRACK_STATS) {
|
||||||
XFREE(ssl_hint->stats, ssl->ctx->heap, DYNAMIC_TYPE_SSL);
|
XFREE(ssl_hint->stats, ssl->heap, DYNAMIC_TYPE_SSL);
|
||||||
}
|
}
|
||||||
XFREE(ssl->heap, ssl->ctx->heap, DYNAMIC_TYPE_SSL);
|
XFREE(ssl->heap, ssl->heap, DYNAMIC_TYPE_SSL);
|
||||||
#ifdef WOLFSSL_HEAP_TEST
|
#ifdef WOLFSSL_HEAP_TEST
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user