@@ -1779,7 +1779,7 @@ static zend_result php_openssl_setup_crypto(php_stream *stream,
17791779 } else {
17801780 verify_peer = true;
17811781 if (FAILURE == php_openssl_enable_peer_verification (sslsock -> ctx , stream )) {
1782- return FAILURE ;
1782+ goto fail ;
17831783 }
17841784 }
17851785
@@ -1797,7 +1797,7 @@ static zend_result php_openssl_setup_crypto(php_stream *stream,
17971797#endif
17981798 if (cipherlist ) {
17991799 if (SSL_CTX_set_cipher_list (sslsock -> ctx , cipherlist ) != 1 ) {
1800- return FAILURE ;
1800+ goto fail ;
18011801 }
18021802 }
18031803
@@ -1820,17 +1820,13 @@ static zend_result php_openssl_setup_crypto(php_stream *stream,
18201820
18211821 if (alpn == NULL ) {
18221822 php_error_docref (NULL , E_WARNING , "Failed parsing comma-separated TLS ALPN protocol string" );
1823- SSL_CTX_free (sslsock -> ctx );
1824- sslsock -> ctx = NULL ;
1825- return FAILURE ;
1823+ goto fail ;
18261824 }
18271825 if (sslsock -> is_client ) {
18281826 if (SSL_CTX_set_alpn_protos (sslsock -> ctx , alpn , alpn_len )) {
18291827 php_error_docref (NULL , E_WARNING , "Failed setting TLS ALPN protocols, protocol names must not be empty" );
18301828 efree (alpn );
1831- SSL_CTX_free (sslsock -> ctx );
1832- sslsock -> ctx = NULL ;
1833- return FAILURE ;
1829+ goto fail ;
18341830 }
18351831 } else {
18361832 sslsock -> alpn_ctx .data = (unsigned char * ) pestrndup ((const char * )alpn , alpn_len , php_stream_is_persistent (stream ));
@@ -1847,7 +1843,7 @@ static zend_result php_openssl_setup_crypto(php_stream *stream,
18471843 }
18481844
18491845 if (FAILURE == php_openssl_set_local_cert (sslsock -> ctx , stream )) {
1850- return FAILURE ;
1846+ goto fail ;
18511847 }
18521848
18531849 SSL_CTX_set_options (sslsock -> ctx , ssl_ctx_options );
@@ -1861,23 +1857,15 @@ static zend_result php_openssl_setup_crypto(php_stream *stream,
18611857 PHP_STREAM_CONTEXT (stream ) &&
18621858 FAILURE == php_openssl_set_server_specific_opts (stream , sslsock -> ctx )
18631859 ) {
1864- return FAILURE ;
1860+ goto fail ;
18651861 }
18661862
18671863 sslsock -> ssl_handle = SSL_new (sslsock -> ctx );
18681864
18691865 if (sslsock -> ssl_handle == NULL
18701866 || !SSL_set_ex_data (sslsock -> ssl_handle , php_openssl_get_ssl_stream_data_index (), stream )) {
18711867 php_error_docref (NULL , E_WARNING , "SSL handle creation failure" );
1872- SSL_CTX_free (sslsock -> ctx );
1873- sslsock -> ctx = NULL ;
1874- #ifdef HAVE_TLS_ALPN
1875- if (sslsock -> alpn_ctx .data ) {
1876- pefree (sslsock -> alpn_ctx .data , php_stream_is_persistent (stream ));
1877- sslsock -> alpn_ctx .data = NULL ;
1878- }
1879- #endif
1880- return FAILURE ;
1868+ goto fail ;
18811869 }
18821870
18831871 if (!SSL_set_fd (sslsock -> ssl_handle , sslsock -> s .socket )) {
@@ -1911,6 +1899,19 @@ static zend_result php_openssl_setup_crypto(php_stream *stream,
19111899 }
19121900
19131901 return SUCCESS ;
1902+
1903+ fail :
1904+ SSL_free (sslsock -> ssl_handle );
1905+ sslsock -> ssl_handle = NULL ;
1906+ SSL_CTX_free (sslsock -> ctx );
1907+ sslsock -> ctx = NULL ;
1908+ #ifdef HAVE_TLS_ALPN
1909+ if (sslsock -> alpn_ctx .data ) {
1910+ pefree (sslsock -> alpn_ctx .data , php_stream_is_persistent (stream ));
1911+ sslsock -> alpn_ctx .data = NULL ;
1912+ }
1913+ #endif
1914+ return FAILURE ;
19141915}
19151916/* }}} */
19161917
0 commit comments