Bug #79881 [NEW]: Memory leak, openssl_pkey_get_public()
| From: | nikita dot korzhitskii at liu dot se | Date: | Tue, 21 Jul 2020 23:11:25 +0000 |
| Subject: | Bug #79881 [NEW]: Memory leak, openssl_pkey_get_public() | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-228166@lists.php.net to get a copy of this message | ||
From: nikita dot korzhitskii at liu dot se
Operating system: Linux, macOS
PHP version: master-Git-2020-07-21 (Git)
Package: OpenSSL related
Bug Type: Bug
Bug description:Memory leak, openssl_pkey_get_public()
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 bug report at https://bugs.php.net/bug.php?id=79881&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79881&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79881&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79881&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79881&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79881&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79881&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79881&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79881&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79881&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79881&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79881&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79881&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79881&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79881&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79881&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79881&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79881&r=mysqlcfg