@@ -101,19 +101,22 @@ int dtls_connect(DTLSManager *m, SocketAddress *address) {
101101
102102 log_debug ("DTLS: Connected to remote server: '%s'" , pretty );
103103
104- ssl = SSL_new (m -> ctx );
105- if (!ssl )
106- return log_error_errno (SYNTHETIC_ERRNO (ENOMEM ),
107- "DTLS: Failed to allocate memory for ssl: %s" ,
108- ERR_error_string (ERR_get_error (), NULL ));
109-
110104 /* Create BIO from socket array! */
111105 bio = BIO_new_dgram (fd , BIO_NOCLOSE );
112106 if (!bio )
113107 return log_error_errno (SYNTHETIC_ERRNO (ENOMEM ),
114108 "DTLS: Failed to allocate memory for bio: %m" );
115109
116110 BIO_ctrl (bio , BIO_CTRL_DGRAM_SET_CONNECTED , 0 , & address );
111+ /* Set and activate timeouts */
112+ BIO_ctrl (bio , BIO_CTRL_DGRAM_SET_RECV_TIMEOUT , 0 , & timeout );
113+
114+ ssl = SSL_new (m -> ctx );
115+ if (!ssl )
116+ return log_error_errno (SYNTHETIC_ERRNO (ENOMEM ),
117+ "DTLS: Failed to allocate memory for ssl: %s" ,
118+ ERR_error_string (ERR_get_error (), NULL ));
119+
117120 SSL_set_bio (ssl , bio , bio );
118121 bio = NULL ;
119122
@@ -154,9 +157,6 @@ int dtls_connect(DTLSManager *m, SocketAddress *address) {
154157 log_debug ("DTLS: No certificates." );
155158 }
156159
157- /* Set and activate timeouts */
158- BIO_ctrl (bio , BIO_CTRL_DGRAM_SET_RECV_TIMEOUT , 0 , & timeout );
159-
160160 m -> ssl = TAKE_PTR (ssl );
161161 m -> fd = TAKE_FD (fd );
162162 m -> pretty_address = TAKE_PTR (pretty );
0 commit comments