diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index 8fc830b756d7..ae8cec7933a2 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -2847,6 +2847,7 @@ PHP_FUNCTION(openssl_pkcs12_read) zout = zend_try_array_init(zout); if (!zout) { + sk_X509_pop_free(ca, X509_free); goto cleanup; } diff --git a/ext/openssl/tests/openssl_pkcs12_read_array_init.phpt b/ext/openssl/tests/openssl_pkcs12_read_array_init.phpt new file mode 100644 index 000000000000..b57cd32b686a --- /dev/null +++ b/ext/openssl/tests/openssl_pkcs12_read_array_init.phpt @@ -0,0 +1,23 @@ +--TEST-- +Memory leak when array initialization in openssl_pkcs12_read() fails +--EXTENSIONS-- +openssl +--FILE-- +foo, "csos"); +} catch (TypeError $e) { + echo $e::class, ": ", $e->getMessage(), "\n"; +} +?> +--EXPECT-- +TypeError: Cannot assign array to reference held by property Typed::$foo of type string