|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79881 Memory leak in openssl_pkey_get_public()
Submitted: 2020-07-21 23:11 UTC Modified: 2020-07-22 08:05 UTC
From: nikita dot korzhitskii at liu dot se Assigned: nikic (profile)
Status: Closed Package: OpenSSL related
PHP Version: 7.3 OS: Linux, macOS
Private report: No CVE-ID: None
 [2020-07-21 23:11 UTC] nikita dot korzhitskii at liu dot se
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:

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


"Fatal error: Allowed memory ... exhausted".


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-07-22 07:46 UTC]
-Status: Open +Status: Verified
 [2020-07-22 08:05 UTC]
-Summary: Memory leak, openssl_pkey_get_public() +Summary: Memory leak in openssl_pkey_get_public() -Status: Verified +Status: Assigned -PHP Version: master-Git-2020-07-21 (Git) +PHP Version: 7.3 -Assigned To: +Assigned To: nikic
 [2020-07-22 08:21 UTC]
Automatic comment on behalf of
Log: Fixed bug #79881
 [2020-07-22 08:21 UTC]
-Status: Assigned +Status: Closed
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Apr 10 12:01:23 2021 UTC