diff options
author | Xiaoming Jiang <jiangxiaoming@outlook.com> | 2023-05-26 00:32:25 +0000 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2023-05-30 16:57:53 +0000 |
commit | fc38603c0173cf6dceb36f0af212db7a8298d203 (patch) | |
tree | df5ec4da05df2087d33ee91810343684f5d0db92 /src | |
parent | b60a6477eb00429c69b08abf2abad64ac4b12c4b (diff) |
tls: fix memory leak when client/server init error
Type: fix
Signed-off-by: Xiaoming Jiang <jiangxiaoming@outlook.com>
Change-Id: I484f3759b6c27052e08741398ec389729285f035
(cherry picked from commit 4778164869395ec9efeeef31fc08f97b93cdff90)
Diffstat (limited to 'src')
-rw-r--r-- | src/vnet/tls/tls.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/vnet/tls/tls.c b/src/vnet/tls/tls.c index b082467c95f..fb625c841c6 100644 --- a/src/vnet/tls/tls.c +++ b/src/vnet/tls/tls.c @@ -463,6 +463,7 @@ tls_session_accept_callback (session_t * tls_session) session_t *tls_listener, *app_session; tls_ctx_t *lctx, *ctx; u32 ctx_handle; + int rv; tls_listener = listen_session_get_from_handle (tls_session->listener_handle); @@ -489,7 +490,14 @@ tls_session_accept_callback (session_t * tls_session) TLS_DBG (1, "Accept on listener %u new connection [%u]%x", tls_listener->opaque, vlib_get_thread_index (), ctx_handle); - return tls_ctx_init_server (ctx); + rv = tls_ctx_init_server (ctx); + if (rv) + { + session_free (app_session); + tls_ctx_free (ctx); + } + + return rv; } int @@ -530,6 +538,7 @@ tls_session_connected_cb (u32 tls_app_index, u32 ho_ctx_index, tls_ctx_t *ho_ctx, *ctx; session_type_t st; u32 ctx_handle; + int rv; ho_ctx = tls_ctx_half_open_get (ho_ctx_index); @@ -559,7 +568,14 @@ tls_session_connected_cb (u32 tls_app_index, u32 ho_ctx_index, app_session->session_type = st; app_session->connection_index = ctx->tls_ctx_handle; - return tls_ctx_init_client (ctx); + rv = tls_ctx_init_client (ctx); + if (rv) + { + session_free (app_session); + tls_ctx_free (ctx); + } + + return rv; } int |