diff --git a/NEWS b/NEWS index 1ab7e3d1bc1..b28590c2574 100644 --- a/NEWS +++ b/NEWS @@ -41,6 +41,9 @@ PHP NEWS - Mbstring: . Fixed bug #79787 (mb_strimwidth does not trim string). (XXiang) +- OpenSSL: + . Fixed bug #79881 (Memory leak in openssl_pkey_get_public()). (Nikita) + - Reflection: . Fixed bug #79487 (::getStaticProperties() ignores property modifications). (cmb, Nikita) diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index 04cb9b0f231..8a45a6cfa25 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -3860,10 +3860,6 @@ static EVP_PKEY * php_openssl_evp_from_zval( if (!what) { TMP_CLEAN; } - if (resourceval) { - *resourceval = res; - Z_ADDREF_P(val); - } if (res->type == le_x509) { /* extract key from cert, depending on public_key param */ cert = (X509*)what; @@ -3887,6 +3883,10 @@ static EVP_PKEY * php_openssl_evp_from_zval( zval_ptr_dtor_str(&tmp); } /* got the key - return it */ + if (resourceval) { + *resourceval = res; + Z_ADDREF_P(val); + } return (EVP_PKEY*)what; } } else { diff --git a/ext/openssl/tests/bug79881.phpt b/ext/openssl/tests/bug79881.phpt new file mode 100644 index 00000000000..915f95bdd4b --- /dev/null +++ b/ext/openssl/tests/bug79881.phpt @@ -0,0 +1,45 @@ +--TEST-- +Bug #79881: Memory leak in openssl_pkey_get_public() +--FILE-- + +--EXPECT-- +bool(true)