diff --git a/ext/mysqlnd/mysqlnd_vio.c b/ext/mysqlnd/mysqlnd_vio.c index e2194bca136a1..2bd77906a1b9a 100644 --- a/ext/mysqlnd/mysqlnd_vio.c +++ b/ext/mysqlnd/mysqlnd_vio.c @@ -561,6 +561,10 @@ MYSQLND_METHOD(mysqlnd_vio, enable_ssl)(MYSQLND_VIO * const net) } } php_stream_context_set(net_stream, context); + /* php_stream_context_set() increases the refcount of context, but we just want to transfer ownership + * hence the need to decrease the refcount so the refcount will be equal to 1. */ + ZEND_ASSERT(GC_REFCOUNT(context->res) == 2); + GC_DELREF(context->res); if (php_stream_xport_crypto_setup(net_stream, STREAM_CRYPTO_METHOD_TLS_CLIENT, NULL) < 0 || php_stream_xport_crypto_enable(net_stream, 1) < 0) {