From: Nikita Popov Date: Wed, 22 Jul 2020 08:20:37 +0000 (+0200) Subject: Fixed bug #79881 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=657a832a77d3c0759dce095b619aa16cd5c360ce;p=php Fixed bug #79881 --- diff --git a/NEWS b/NEWS index 1ab7e3d1bc..b28590c257 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 04cb9b0f23..8a45a6cfa2 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 0000000000..915f95bdd4 --- /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)