From bd2e82082955aa3fd64cddda98d69acf5e918032 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Tue, 14 Nov 2017 22:21:08 +0100 Subject: [PATCH] Fix double-free when closing mbedTLS connections Partly revert commit 0486100a2bcbce74a7214ee4f11782a9441acbf0 from 07.08.2017 as it breaks layering: every layer must free its own altcp_pcb. Freeing the inner_conn is not the right way. --- src/apps/altcp_tls/altcp_tls_mbedtls.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/apps/altcp_tls/altcp_tls_mbedtls.c b/src/apps/altcp_tls/altcp_tls_mbedtls.c index de60801e..02f0fd4c 100644 --- a/src/apps/altcp_tls/altcp_tls_mbedtls.c +++ b/src/apps/altcp_tls/altcp_tls_mbedtls.c @@ -563,6 +563,8 @@ altcp_mbedtls_setup(void *conf, struct altcp_pcb *conn, struct altcp_pcb *inner_ if (!conf) { return ERR_ARG; } + LWIP_ASSERT("invalid inner_conn", conn != inner_conn); + /* allocate mbedtls context */ state = altcp_mbedtls_alloc(conf); if (state == NULL) { @@ -970,10 +972,6 @@ altcp_mbedtls_dealloc(struct altcp_pcb *conn) altcp_mbedtls_free(state->conf, state); conn->state = NULL; } - if (conn->inner_conn) { - altcp_free(conn->inner_conn); - conn->inner_conn = NULL; - } } }