MbedTLS: Move memory allocation to the beginning of rb_ssl_init_fd

This commit is contained in:
Aaron Jones 2016-09-15 11:39:00 +00:00
parent 163a4a9d06
commit 978c8ae828
No known key found for this signature in database
GPG key ID: EC6F86EE9CD840B5

View file

@ -121,6 +121,15 @@ rb_mbedtls_cfg_decref(rb_mbedtls_cfg_context *const cfg)
static void static void
rb_ssl_init_fd(rb_fde_t *const F, rb_fd_tls_direction dir) 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; mbedtls_ssl_config *mbed_config;
switch(dir) switch(dir)
@ -133,15 +142,6 @@ rb_ssl_init_fd(rb_fde_t *const F, rb_fd_tls_direction dir)
break; 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_init(&mbed_ssl_ctx->ssl);
mbedtls_ssl_set_bio(&mbed_ssl_ctx->ssl, F, rb_sock_net_xmit, rb_sock_net_recv, NULL); mbedtls_ssl_set_bio(&mbed_ssl_ctx->ssl, F, rb_sock_net_xmit, rb_sock_net_recv, NULL);