@@ -141,7 +141,7 @@ typedef struct _php_openssl_netstream_data_t {
141
141
php_openssl_sni_cert_t * sni_certs ;
142
142
unsigned sni_cert_count ;
143
143
#ifdef HAVE_TLS_ALPN
144
- php_openssl_alpn_ctx * alpn_ctx ;
144
+ php_openssl_alpn_ctx alpn_ctx ;
145
145
#endif
146
146
char * url_name ;
147
147
unsigned state_set :1 ;
@@ -1453,9 +1453,7 @@ static int server_alpn_callback(SSL *ssl_handle, const unsigned char **out, unsi
1453
1453
{
1454
1454
php_openssl_netstream_data_t * sslsock = arg ;
1455
1455
1456
- if (SSL_select_next_proto
1457
- ((unsigned char * * )out , outlen , sslsock -> alpn_ctx -> data , sslsock -> alpn_ctx -> len , in ,
1458
- inlen ) != OPENSSL_NPN_NEGOTIATED ) {
1456
+ if (SSL_select_next_proto ((unsigned char * * )out , outlen , sslsock -> alpn_ctx .data , sslsock -> alpn_ctx .len , in , inlen ) != OPENSSL_NPN_NEGOTIATED ) {
1459
1457
return SSL_TLSEXT_ERR_NOACK ;
1460
1458
}
1461
1459
@@ -1564,9 +1562,8 @@ int php_openssl_setup_crypto(php_stream *stream,
1564
1562
if (sslsock -> is_client ) {
1565
1563
SSL_CTX_set_alpn_protos (sslsock -> ctx , alpn , alpn_len );
1566
1564
} else {
1567
- sslsock -> alpn_ctx = (php_openssl_alpn_ctx * ) emalloc (sizeof (php_openssl_alpn_ctx ));
1568
- sslsock -> alpn_ctx -> data = (unsigned char * )estrndup ((const char * )alpn , alpn_len );
1569
- sslsock -> alpn_ctx -> len = alpn_len ;
1565
+ sslsock -> alpn_ctx .data = (unsigned char * ) pestrndup ((const char * )alpn , alpn_len , php_stream_is_persistent (stream ));
1566
+ sslsock -> alpn_ctx .len = alpn_len ;
1570
1567
SSL_CTX_set_alpn_select_cb (sslsock -> ctx , server_alpn_callback , sslsock );
1571
1568
}
1572
1569
@@ -1597,6 +1594,12 @@ int php_openssl_setup_crypto(php_stream *stream,
1597
1594
php_error_docref (NULL , E_WARNING , "SSL handle creation failure" );
1598
1595
SSL_CTX_free (sslsock -> ctx );
1599
1596
sslsock -> ctx = NULL ;
1597
+ #ifdef HAVE_TLS_ALPN
1598
+ if (sslsock -> alpn_ctx .data ) {
1599
+ pefree (sslsock -> alpn_ctx .data , php_stream_is_persistent (stream ));
1600
+ sslsock -> alpn_ctx .data = NULL ;
1601
+ }
1602
+ #endif
1600
1603
return FAILURE ;
1601
1604
} else {
1602
1605
SSL_set_ex_data (sslsock -> ssl_handle , php_openssl_get_ssl_stream_data_index (), stream );
@@ -2098,6 +2101,11 @@ static int php_openssl_sockop_close(php_stream *stream, int close_handle) /* {{{
2098
2101
SSL_CTX_free (sslsock -> ctx );
2099
2102
sslsock -> ctx = NULL ;
2100
2103
}
2104
+ #ifdef HAVE_TLS_ALPN
2105
+ if (sslsock -> alpn_ctx .data ) {
2106
+ pefree (sslsock -> alpn_ctx .data , php_stream_is_persistent (stream ));
2107
+ }
2108
+ #endif
2101
2109
#ifdef PHP_WIN32
2102
2110
if (sslsock -> s .socket == -1 )
2103
2111
sslsock -> s .socket = SOCK_ERR ;
0 commit comments