From: chuanm at gmail dot com
Operating system: centos 6.4
PHP version: 5.4.26
Package: OpenSSL related
Bug Type: Bug
Bug description:memory leak in openssl_seal()
Description:
------------
### Compiled with:
./confgiure --with-openssl --with-openssl-dir=/usr/lib64/openssl
### create keys
openssl genrsa -out privkey.pem 2048
openssl rsa -pubout -in privkey.pem -out pubkey.pem
Test script:
---------------
<?php
$data = 'this is test';
$cert = <<<ABC
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA01/7gxSlhLff2iKBNBIA
N77U+cdLl2g/YaJNjp4TQI33QY+P5VtP7coBxY2KyfhZAValyGmCzugSt4IlG/Jd
5FT+JSosUbbKSuSs4lia8mge0h7V5ius5ZvWTIqxtMtoxx36HLoaj4KQ32ToZjYM
/wI2ZMW9KD8WTFdezW7IKzc89DJ3AaoZaobRvUOjZVg8giLvsAFk4T3oWPS37Zed
uE4LkFdTnLxQ5y1rFWELpqm7E2itB+nLxHEq1Sb1w22iyXGqQSmaXC/b4SmjDLVw
W1lPjmYJt4NGNTgi3EAGWpCHnn9z1ERcOYX8lg+vTGftvejDgv/zvAuoWKiUO9lk
ywIDAQAB
-----END PUBLIC KEY-----
ABC;
$pk1 = openssl_get_publickey($cert);
openssl_seal($data, $sealed, $ekeys, array($pk1));
Expected result:
----------------
valgrind run should not complain about memory leak.
Actual result:
--------------
bash-4.1# valgrind --leak-check=full php openssl.php
==25769== Memcheck, a memory error detector
==25769== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et
al.
==25769== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright
info
==25769== Command: php openssl.php
==25769==
==25769==
==25769== HEAP SUMMARY:
==25769== in use at exit: 84,649 bytes in 2,704 blocks
==25769== total heap usage: 15,468 allocs, 12,764 frees, 3,234,966
bytes allocated
==25769==
==25769== 1,032 bytes in 1 blocks are definitely lost in loss record 64
of 87
==25769== at 0x4C279EE: malloc (vg_replace_malloc.c:270)
==25769== by 0x614AB2D: CRYPTO_malloc (in
/usr/lib64/libcrypto.so.1.0.1e)
==25769== by 0x61CA808: EVP_CipherInit_ex (in
/usr/lib64/libcrypto.so.1.0.1e)
==25769== by 0x45E46B: zif_openssl_seal (openssl.c:4318)
==25769== by 0x6FD7A9: zend_do_fcall_common_helper_SPEC
(zend_vm_execute.h:643)
==25769== by 0x6F1BAF: execute (zend_vm_execute.h:410)
==25769== by 0x68BD4D: zend_execute_scripts (zend.c:1315)
==25769== by 0x631BED: php_execute_script (main.c:2502)
==25769== by 0x7320D2: do_cli (php_cli.c:989)
==25769== by 0x7327C3: main (php_cli.c:1365)
==25769==
==25769== 1,032 bytes in 1 blocks are definitely lost in loss record 65
of 87
==25769== at 0x4C279EE: malloc (vg_replace_malloc.c:270)
==25769== by 0x614AB2D: CRYPTO_malloc (in
/usr/lib64/libcrypto.so.1.0.1e)
==25769== by 0x61CA808: EVP_CipherInit_ex (in
/usr/lib64/libcrypto.so.1.0.1e)
==25769== by 0x61D0B7C: EVP_SealInit (in
/usr/lib64/libcrypto.so.1.0.1e)
==25769== by 0x45E58D: zif_openssl_seal (openssl.c:4331)
==25769== by 0x6FD7A9: zend_do_fcall_common_helper_SPEC
(zend_vm_execute.h:643)
==25769== by 0x6F1BAF: execute (zend_vm_execute.h:410)
==25769== by 0x68BD4D: zend_execute_scripts (zend.c:1315)
==25769== by 0x631BED: php_execute_script (main.c:2502)
==25769== by 0x7320D2: do_cli (php_cli.c:989)
==25769== by 0x7327C3: main (php_cli.c:1365)
==25769==
==25769== LEAK SUMMARY:
==25769== definitely lost: 2,064 bytes in 2 blocks
==25769== indirectly lost: 0 bytes in 0 blocks
==25769== possibly lost: 0 bytes in 0 blocks
==25769== still reachable: 82,585 bytes in 2,702 blocks
==25769== suppressed: 0 bytes in 0 blocks
==25769== Reachable blocks (those to which a pointer was found) are not
shown.
==25769== To see them, rerun with: --leak-check=full
--show-reachable=yes
==25769==
==25769== For counts of detected and suppressed errors, rerun with: -v
==25769== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 6 from 6)
--
Edit bug report at https://bugs.php.net/bug.php?id=66942&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66942&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66942&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66942&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66942&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66942&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66942&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66942&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66942&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66942&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66942&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66942&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66942&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66942&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66942&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66942&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66942&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66942&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66942&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66942&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66942&r=mysqlcfg