@@ -211,8 +211,11 @@ struct mosquitto *net__socket_accept(struct mosquitto__listener_sock *listensock
211211 context__cleanup (new_context , true);
212212 return NULL ;
213213 }
214- SSL_set_ex_data (new_context -> ssl , tls_ex_index_context , new_context );
215- SSL_set_ex_data (new_context -> ssl , tls_ex_index_listener , new_context -> listener );
214+ if (!SSL_set_ex_data (new_context -> ssl , tls_ex_index_context , new_context )
215+ || !SSL_set_ex_data (new_context -> ssl , tls_ex_index_listener , new_context -> listener )){
216+ context__cleanup (new_context , true);
217+ return NULL ;
218+ }
216219 new_context -> want_write = true;
217220 bio = BIO_new_socket (new_sock , BIO_NOCLOSE );
218221 SSL_set_bio (new_context -> ssl , bio , bio );
@@ -321,6 +324,13 @@ int net__tls_server_ctx(struct mosquitto__listener *listener)
321324 FILE * dhparamfile ;
322325 DH * dhparam = NULL ;
323326
327+ if (tls_ex_index_context == -1 ){
328+ tls_ex_index_context = SSL_get_ex_new_index (0 , "client context" , NULL , NULL , NULL );
329+ }
330+ if (tls_ex_index_listener == -1 ){
331+ tls_ex_index_listener = SSL_get_ex_new_index (0 , "listener" , NULL , NULL , NULL );
332+ }
333+
324334 if (listener -> ssl_ctx ){
325335 SSL_CTX_free (listener -> ssl_ctx );
326336 }
@@ -918,13 +928,6 @@ int net__socket_listen(struct mosquitto__listener *listener)
918928 }
919929# ifdef FINAL_WITH_TLS_PSK
920930 if (listener -> psk_hint ){
921- if (tls_ex_index_context == -1 ){
922- tls_ex_index_context = SSL_get_ex_new_index (0 , "client context" , NULL , NULL , NULL );
923- }
924- if (tls_ex_index_listener == -1 ){
925- tls_ex_index_listener = SSL_get_ex_new_index (0 , "listener" , NULL , NULL , NULL );
926- }
927-
928931 if (listener -> certfile == NULL || listener -> keyfile == NULL ){
929932 if (net__tls_server_ctx (listener )){
930933 return 1 ;
0 commit comments