Skip to content

Commit 095d9cf

Browse files
author
Hanno Becker
committed
Fix ordering of free()ing of internal structures in ssl_server2
If `MBEDTLS_MEMORY_BUFFER_ALLOC_C` is configured and Mbed TLS' custom buffer allocator is used for calloc() and free(), the read buffer used by the server example application is allocated from the buffer allocator, but freed after the buffer allocator has been destroyed. If memory backtracing is enabled, this leaves a memory leak in the backtracing structure allocated for the buffer, as found by valgrind. Fixes Mbed-TLS#2069.
1 parent 0592ea7 commit 095d9cf

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

programs/ssl/ssl_server2.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -3146,14 +3146,15 @@ int main( int argc, char *argv[] )
31463146
mbedtls_ssl_cookie_free( &cookie_ctx );
31473147
#endif
31483148

3149+
mbedtls_free( buf );
3150+
31493151
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
31503152
#if defined(MBEDTLS_MEMORY_DEBUG)
31513153
mbedtls_memory_buffer_alloc_status();
31523154
#endif
31533155
mbedtls_memory_buffer_alloc_free();
31543156
#endif
31553157

3156-
mbedtls_free( buf );
31573158
mbedtls_printf( " done.\n" );
31583159

31593160
#if defined(_WIN32)

0 commit comments

Comments
 (0)