Bug #79881 [Opn->Ver]: Memory leak, openssl_pkey_get_public()
| From: | nikic@php.net | Date: | Wed, 22 Jul 2020 07:46:53 +0000 |
| Subject: | Bug #79881 [Opn->Ver]: Memory leak, openssl_pkey_get_public() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-228169@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79881&edit=1
ID: 79881
Updated by: nikic@php.net
Reported by: nikita dot korzhitskii at liu dot se
Summary: Memory leak, openssl_pkey_get_public()
-Status: Open
+Status: Verified
Type: Bug
Package: OpenSSL related
Operating System: Linux, macOS
PHP Version: master-Git-2020-07-21 (Git)
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2020-07-21 23:11:25] nikita dot korzhitskii at liu dot se
Description:
------------
Memory seems to be leaking, when extracting public keys from x509 certificates with
openssl_pkey_get_public(). Resources do not free automatically, with openssl_pkey_free(), unset(),
or null-assignment.
The leakage is observed on
PHP 7.1.23 macOS Darwin Kernel Version 18.7.0 + LibreSSL 2.2.7/2.6.5,
PHP 7.2.24-0ubuntu0.18.04.6 + OpenSSL/1.1.1
PHP 8.0.0-dev Ubuntu + OpenSSL/1.1.1
The test script is provided.
Test script:
---------------
https://gist.github.com/nikita-kun/88b80583a4d12230910040cf2cd3031d
Expected result:
----------------
Constant memory usage
Actual result:
--------------
Memory usage, real: 2097152
Memory usage, real: 4194304
Memory usage, real: 6295552
...
Memory usage, real: 106958848
Memory usage, real: 109056000
Warning: openssl_x509_read(): Supplied parameter cannot be coerced into an X509 certificate! in
./php-src/memleak.php on line 38
Fatal error: Uncaught TypeError: openssl_pkey_free(): Argument #1 ($key) must be of type resource,
bool given in ./php-src/memleak.php:41
Stack trace:
#0 ./php-src/memleak.php(41): openssl_pkey_free(false)
#1 ./php-src/memleak.php(56): fastLeakage()
#2 {main}
thrown in ./php-src/memleak.php on line 41
Killed
OR
"Fatal error: Allowed memory ... exhausted".
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79881&edit=1