CaBundle openssl 内存泄露问题

mmap() failed: [12] Cannot allocate memory
PHP Fatal error: Out of memory (allocated 81788928) (tried to allocate 14987979559889010744 bytes) in phar:///usr/local/bin/composer/vendor/composer/ca-bundle/src/CaBundle.php on line 167



openssl_x509_parse调用之后内存泄漏



$x509data = file_get_contents ( “d:/certs/xxx.cer” );
$resource = openssl_x509_read ( $x509data );
$certdata = openssl_x509_parse ( $resource ); //<=就是这句有问题
echo $certdata [‘serialNumber’]; //<=就是需要这个数据所以要调上面那句
echo $x509data;
unset($certdata); //<=似乎没有什么用
openssl_x509_free($resource); //<=似乎没有什么用x2



循环个100000次可以看到明显一直在涨。
windows下试过php5.4+openssl0.9.8,php7.0+openssl1.0.2都有这问题。



https://www.jianshu.com/p/12a1dc4ab7a0



https://www.openssl.org/source/



https://github.com/openssl/openssl/tags?after=OpenSSL_1_0_2u



https://github.com/openssl/openssl



https://www.jb51.net/article/144387.htm



https://bugs.php.net/bug.php?id=65602%20



https://www.cnblogs.com/coolYuan/p/8963972.html



curl -O https://github.com/openssl/openssl/archive/OpenSSL_1_1_0l.tar.gz



curl -O https://github.com/openssl/openssl/archive/OpenSSL_1_1_0l.zip



$tar -zxvf OpenSSL_1_0_2t.tar.gz
tar: Unrecognized archive format
tar: Error exit delayed from previous errors.



git clone https://github.com/openssl/openssl



$brew install openssl
^C
Warning: You are using macOS 10.11.
We (and Apple) do not provide support for this old version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew’s GitHub,
Discourse, Twitter or IRC. You are responsible for resolving any issues you
experience while you are running this old version.



==> Downloading https://www.openssl.org/source/openssl-1.1.1g.tar.gz
######

==> perl ./Configure –prefix=/usr/local/Cellar/openssl@1.1/1.1.1g –openssldir=/usr/local/etc/openssl@1.1 no-ssl3 n
==> make



==> make install MANDIR=/usr/local/Cellar/openssl@1.1/1.1.1g/share/man MANSUFFIX=ssl
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl@1.1/certs



and run
/usr/local/opt/openssl@1.1/bin/c_rehash



openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.



If you need to have openssl@1.1 first in your PATH run:
echo ‘export PATH=”/usr/local/opt/openssl@1.1/bin:$PATH”’ » /Users/didi/.bash_profile



For compilers to find openssl@1.1 you may need to set:
export LDFLAGS=”-L/usr/local/opt/openssl@1.1/lib”
export CPPFLAGS=”-I/usr/local/opt/openssl@1.1/include”



For pkg-config to find openssl@1.1 you may need to set:
export PKG_CONFIG_PATH=”/usr/local/opt/openssl@1.1/lib/pkgconfig”



curl -O https://www.openssl.org/source/openssl-1.1.1g.tar.gz



526  tar -zxvf openssl-1.1.1g.tar.gz   527  cd openssl-1.1.1g

528 ./Configure darwin64-x86_64-cc -shared --prefix=/usr/local 529 sudo make -j4 530 sudo make install


$ openssl version
OpenSSL 1.1.1g 21 Apr 2020



cd ..



537  make clean   538  ./configure   539  make -j4


/Users/didi/PhpstormProjects/c/php-src/ext/openssl/openssl.c:3620:6: error: incomplete definition of type
‘struct dsa_st’



  高版本问题是和php7.0 不兼容
低版本内存泄露


Category php