From 978c8ae828fd6af926eea7d3a3c7a600e67c0440 Mon Sep 17 00:00:00 2001 From: Aaron Jones Date: Thu, 15 Sep 2016 11:39:00 +0000 Subject: [PATCH] MbedTLS: Move memory allocation to the beginning of rb_ssl_init_fd --- libratbox/src/mbedtls.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libratbox/src/mbedtls.c b/libratbox/src/mbedtls.c index 35315233..053bb281 100644 --- a/libratbox/src/mbedtls.c +++ b/libratbox/src/mbedtls.c @@ -121,6 +121,15 @@ rb_mbedtls_cfg_decref(rb_mbedtls_cfg_context *const cfg) static void rb_ssl_init_fd(rb_fde_t *const F, rb_fd_tls_direction dir) { + rb_mbedtls_ssl_context *const mbed_ssl_ctx = rb_malloc(sizeof *mbed_ssl_ctx); + + if(mbed_ssl_ctx == NULL) + { + rb_lib_log("rb_ssl_init_fd: rb_malloc: allocation failure"); + rb_close(F); + return; + } + mbedtls_ssl_config *mbed_config; switch(dir) @@ -133,15 +142,6 @@ rb_ssl_init_fd(rb_fde_t *const F, rb_fd_tls_direction dir) break; } - rb_mbedtls_ssl_context *const mbed_ssl_ctx = rb_malloc(sizeof *mbed_ssl_ctx); - - if(mbed_ssl_ctx == NULL) - { - rb_lib_log("rb_ssl_init_fd: rb_malloc: allocation failure"); - rb_close(F); - return; - } - mbedtls_ssl_init(&mbed_ssl_ctx->ssl); mbedtls_ssl_set_bio(&mbed_ssl_ctx->ssl, F, rb_sock_net_xmit, rb_sock_net_recv, NULL);