Edit report at http://bugs.php.net/bug.php?id=51347&edit=1
ID: 51347 Comment by: mat999 at gmail dot com Reported by: mat999 at gmail dot com Summary: mysqli_close / connection memory leak Status: Open Type: Bug Package: MySQLi related Operating System: Debian Lenny / Linux PHP Version: 5.3.2 New Comment: Gee, no responses on a proven bug... Heres valgrind info, sorry no debug symbols for php5-mysql [...] ==49959== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 52 from 4) --49959-- --49959-- supp: 22 dl-hack4-64bit-addr-1 --49959-- supp: 2 dl-hack3-cond-2 --49959-- supp: 27 dl-hack3-cond-1 --49959-- supp: 1 dl-hack4-64bit-addr-2 ==49959== malloc/free: in use at exit: 6,394 bytes in 22 blocks. ==49959== malloc/free: 31,095 allocs, 31,073 frees, 4,718,692 bytes allocated. ==49959== ==49959== searching for pointers to 22 not-freed blocks. ==49959== checked 1,626,688 bytes. ==49959== ==49959== 5 bytes in 1 blocks are indirectly lost in loss record 1 of 11 ==49959== at 0x4C2260E: malloc (vg_replace_malloc.c:207) ==49959== by 0x9161D71: strdup (in /lib/libc-2.7.so) ==49959== by 0x91A0036: (within /lib/libc-2.7.so) ==49959== by 0x91A1F78: getaddrinfo (in /lib/libc-2.7.so) ==49959== by 0xA5C017E: ??? ==49959== by 0xA5C030D: ??? ==49959== by 0xA5C0488: ??? ==49959== by 0xA5C04A9: ??? ==49959== by 0xA5C7D96: ??? ==49959== by 0xA38C5FC: ??? ==49959== by 0x74A6CA: zend_startup_module_ex (in /usr/bin/php5) ==49959== by 0x752E3A: zend_hash_apply (in /usr/bin/php5) ==49959== ==49959== ==49959== 12 bytes in 1 blocks are still reachable in loss record 2 of 11 ==49959== at 0x4C2260E: malloc (vg_replace_malloc.c:207) ==49959== by 0x9161D71: strdup (in /lib/libc-2.7.so) ==49959== by 0x555354: zm_startup_intl (in /usr/bin/php5) ==49959== by 0x74A6CA: zend_startup_module_ex (in /usr/bin/php5) ==49959== by 0x752E3A: zend_hash_apply (in /usr/bin/php5) ==49959== by 0x74DC29: zend_startup_modules (in /usr/bin/php5) ==49959== by 0x6F1399: php_module_startup (in /usr/bin/php5) ==49959== by 0x7D7B4C: php_cli_startup (in /usr/bin/php5) ==49959== by 0x7D850F: main (in /usr/bin/php5) ==49959== ==49959== ==49959== 12 bytes in 1 blocks are still reachable in loss record 3 of 11 ==49959== at 0x4C2260E: malloc (vg_replace_malloc.c:207) ==49959== by 0x777588D: uprv_getDefaultLocaleID_3_8 (in /usr/lib/libicuuc.so.38.1) ==49959== by 0x77AC129: (within /usr/lib/libicuuc.so.38.1) ==49959== by 0x77AC2AE: icu_3_8::Locale::getDefault() (in /usr/lib/libicuuc.so.38.1) ==49959== by 0x77AD7C8: (within /usr/lib/libicuuc.so.38.1) ==49959== by 0x55534C: zm_startup_intl (in /usr/bin/php5) ==49959== by 0x74A6CA: zend_startup_module_ex (in /usr/bin/php5) ==49959== by 0x752E3A: zend_hash_apply (in /usr/bin/php5) ==49959== by 0x74DC29: zend_startup_modules (in /usr/bin/php5) ==49959== by 0x6F1399: php_module_startup (in /usr/bin/php5) ==49959== by 0x7D7B4C: php_cli_startup (in /usr/bin/php5) ==49959== by 0x7D850F: main (in /usr/bin/php5) ==49959== ==49959== ==49959== 32 bytes in 1 blocks are still reachable in loss record 4 of 11 ==49959== at 0x4C203E4: calloc (vg_replace_malloc.c:397) ==49959== by 0x66C73DF: (within /lib/libdl-2.7.so) ==49959== by 0x66C6F20: dlopen (in /lib/libdl-2.7.so) ==49959== by 0x752274: zend_load_extension (in /usr/bin/php5) ==49959== by 0x73D30D: zend_llist_apply (in /usr/bin/php5) ==49959== by 0x6F8226: php_ini_register_extensions (in /usr/bin/php5) ==49959== by 0x6F1394: php_module_startup (in /usr/bin/php5) ==49959== by 0x7D7B4C: php_cli_startup (in /usr/bin/php5) ==49959== by 0x7D850F: main (in /usr/bin/php5) ==49959== ==49959== ==49959== 53 bytes in 2 blocks are definitely lost in loss record 5 of 11 ==49959== at 0x4C2260E: malloc (vg_replace_malloc.c:207) ==49959== by 0xA5BF317: ??? ==49959== by 0xA5C0269: ??? ==49959== by 0xA5C030D: ??? ==49959== by 0xA5C0488: ??? ==49959== by 0xA5C04A9: ??? ==49959== by 0xA5C7D96: ??? ==49959== by 0xA38C5FC: ??? ==49959== by 0x74A6CA: zend_startup_module_ex (in /usr/bin/php5) ==49959== by 0x752E3A: zend_hash_apply (in /usr/bin/php5) ==49959== by 0x74DC29: zend_startup_modules (in /usr/bin/php5) ==49959== by 0x6F1399: php_module_startup (in /usr/bin/php5) ==49959== ==49959== ==49959== 69 (64 direct, 5 indirect) bytes in 1 blocks are definitely lost in loss record 6 of 11 ==49959== at 0x4C2260E: malloc (vg_replace_malloc.c:207) ==49959== by 0x919FC83: (within /lib/libc-2.7.so) ==49959== by 0x91A1F78: getaddrinfo (in /lib/libc-2.7.so) ==49959== by 0xA5C017E: ??? ==49959== by 0xA5C030D: ??? ==49959== by 0xA5C0488: ??? ==49959== by 0xA5C04A9: ??? ==49959== by 0xA5C7D96: ??? ==49959== by 0xA38C5FC: ??? ==49959== by 0x74A6CA: zend_startup_module_ex (in /usr/bin/php5) ==49959== by 0x752E3A: zend_hash_apply (in /usr/bin/php5) ==49959== by 0x74DC29: zend_startup_modules (in /usr/bin/php5) ==49959== ==49959== ==49959== 176 bytes in 1 blocks are still reachable in loss record 7 of 11 ==49959== at 0x4C2260E: malloc (vg_replace_malloc.c:207) ==49959== by 0x77AC169: (within /usr/lib/libicuuc.so.38.1) ==49959== by 0x77AC2AE: icu_3_8::Locale::getDefault() (in /usr/lib/libicuuc.so.38.1) ==49959== by 0x77AD7C8: (within /usr/lib/libicuuc.so.38.1) ==49959== by 0x55534C: zm_startup_intl (in /usr/bin/php5) ==49959== by 0x74A6CA: zend_startup_module_ex (in /usr/bin/php5) ==49959== by 0x752E3A: zend_hash_apply (in /usr/bin/php5) ==49959== by 0x74DC29: zend_startup_modules (in /usr/bin/php5) ==49959== by 0x6F1399: php_module_startup (in /usr/bin/php5) ==49959== by 0x7D7B4C: php_cli_startup (in /usr/bin/php5) ==49959== by 0x7D850F: main (in /usr/bin/php5) ==49959== ==49959== ==49959== 672 bytes in 1 blocks are still reachable in loss record 8 of 11 ==49959== at 0x4C2260E: malloc (vg_replace_malloc.c:207) ==49959== by 0x4011429: (within /lib/ld-2.7.so) ==49959== by 0x4011A24: (within /lib/ld-2.7.so) ==49959== by 0x400D385: (within /lib/ld-2.7.so) ==49959== by 0x401111A: (within /lib/ld-2.7.so) ==49959== by 0x66C6FBA: (within /lib/libdl-2.7.so) ==49959== by 0x400D385: (within /lib/ld-2.7.so) ==49959== by 0x66C736B: (within /lib/libdl-2.7.so) ==49959== by 0x66C6F20: dlopen (in /lib/libdl-2.7.so) ==49959== by 0x66A870: php_load_extension (in /usr/bin/php5) ==49959== by 0x73D30D: zend_llist_apply (in /usr/bin/php5) ==49959== by 0x6F8239: php_ini_register_extensions (in /usr/bin/php5) ==49959== ==49959== ==49959== 1,272 bytes in 11 blocks are still reachable in loss record 9 of 11 ==49959== at 0x4C2260E: malloc (vg_replace_malloc.c:207) ==49959== by 0x59BB8F2: CRYPTO_malloc (in /usr/lib/libcrypto.so.0.9.8) ==49959== by 0x5A1C2DE: sk_new (in /usr/lib/libcrypto.so.0.9.8) ==49959== by 0x572D649: (within /usr/lib/libssl.so.0.9.8) ==49959== by 0x572D858: SSL_COMP_get_compression_methods (in /usr/lib/libssl.so.0.9.8) ==49959== by 0x5733A0F: SSL_library_init (in /usr/lib/libssl.so.0.9.8) ==49959== by 0x468BCE: zm_startup_openssl (in /usr/bin/php5) ==49959== by 0x74A6CA: zend_startup_module_ex (in /usr/bin/php5) ==49959== by 0x752E3A: zend_hash_apply (in /usr/bin/php5) ==49959== by 0x74DC29: zend_startup_modules (in /usr/bin/php5) ==49959== by 0x6F1399: php_module_startup (in /usr/bin/php5) ==49959== by 0x7D7B4C: php_cli_startup (in /usr/bin/php5) ==49959== ==49959== ==49959== 2,048 bytes in 1 blocks are still reachable in loss record 10 of 11 ==49959== at 0x4C2260E: malloc (vg_replace_malloc.c:207) ==49959== by 0x753619: _zend_hash_init (in /usr/bin/php5) ==49959== by 0x75366C: _zend_hash_init_ex (in /usr/bin/php5) ==49959== by 0x7472D5: zend_startup (in /usr/bin/php5) ==49959== by 0x6F0DCF: php_module_startup (in /usr/bin/php5) ==49959== by 0x7D7B4C: php_cli_startup (in /usr/bin/php5) ==49959== by 0x7D850F: main (in /usr/bin/php5) ==49959== ==49959== ==49959== 2,048 bytes in 1 blocks are still reachable in loss record 11 of 11 ==49959== at 0x4C2260E: malloc (vg_replace_malloc.c:207) ==49959== by 0x73DC8D: zend_llist_init (in /usr/bin/php5) ==49959== by 0x6FA902: sapi_activate (in /usr/bin/php5) ==49959== by 0x6F0CB3: php_module_startup (in /usr/bin/php5) ==49959== by 0x7D7B4C: php_cli_startup (in /usr/bin/php5) ==49959== by 0x7D850F: main (in /usr/bin/php5) ==49959== ==49959== LEAK SUMMARY: ==49959== definitely lost: 117 bytes in 3 blocks. ==49959== indirectly lost: 5 bytes in 1 blocks. ==49959== possibly lost: 0 bytes in 0 blocks. ==49959== still reachable: 6,272 bytes in 18 blocks. ==49959== suppressed: 0 bytes in 0 blocks. --49959-- memcheck: sanity checks: 50 cheap, 4 expensive --49959-- memcheck: auxmaps: 0 auxmap entries (0k, 0M) in use --49959-- memcheck: auxmaps_L1: 0 searches, 0 cmps, ratio 0:10 --49959-- memcheck: auxmaps_L2: 0 searches, 0 nodes --49959-- memcheck: SMs: n_issued = 161 (2576k, 2M) --49959-- memcheck: SMs: n_deissued = 9 (144k, 0M) --49959-- memcheck: SMs: max_noaccess = 524287 (8388592k, 8191M) --49959-- memcheck: SMs: max_undefined = 14 (224k, 0M) --49959-- memcheck: SMs: max_defined = 2155 (34480k, 33M) --49959-- memcheck: SMs: max_non_DSM = 160 (2560k, 2M) --49959-- memcheck: max sec V bit nodes: 8 (0k, 0M) --49959-- memcheck: set_sec_vbits8 calls: 13 (new: 8, updates: 5) --49959-- memcheck: max shadow mem size: 6704k, 6M --49959-- translate: fast SP updates identified: 21,056 ( 84.1%) --49959-- translate: generic_known SP updates identified: 3,640 ( 14.5%) --49959-- translate: generic_unknown SP updates identified: 331 ( 1.3%) --49959-- tt/tc: 44,478 tt lookups requiring 53,263 probes --49959-- tt/tc: 44,478 fast-cache updates, 24 flushes --49959-- transtab: new 18,748 (589,533 -> 7,876,845; ratio 133:10) [0 scs] --49959-- transtab: dumped 0 (0 -> ??) --49959-- transtab: discarded 1,820 (46,106 -> ??) --49959-- scheduler: 5,020,598 jumps (bb entries). --49959-- scheduler: 50/88,483 major/minor sched events. --49959-- sanity: 51 cheap, 4 expensive checks. --49959-- exectx: 12,289 lists, 10,787 contexts (avg 0 per list) --49959-- exectx: 62,188 searches, 59,102 full compares (950 per 1000) --49959-- exectx: 65 cmp2, 444 cmp4, 0 cmpAll --49959-- errormgr: 44 supplist searches, 1,362 comparisons during search --49959-- errormgr: 52 errlist searches, 607 comparisons during search Previous Comments: ------------------------------------------------------------------------ [2010-04-01 14:46:23] and...@php.net Automatic comment from SVN on behalf of andrey Revision: http://svn.php.net/viewvc/?view=revision&revision=297274 Log: Better fix for bug #51347 mysqli_close / connection memory leak ------------------------------------------------------------------------ [2010-04-01 13:50:26] and...@php.net Automatic comment from SVN on behalf of andrey Revision: http://svn.php.net/viewvc/?view=revision&revision=297271 Log: Fixed bug #51347 mysqli_close / connection memory leak Streams API registers every stream as resource, which lands then in EG(regular_list), however doesn't clean that when the stream is closed. At the end this is a para-leak. At the end of the script all memory is cleaned, however this is a problem for long runnig scripts that open connections. For every opened and closed connection about 150 Bytes on 32bit and 250 Bytes on 64bit will be "lost", according to memory_get_usage(). ------------------------------------------------------------------------ [2010-03-24 23:52:00] mat999 at gmail dot com Yes that is the result obtained with that ENV var set, howeaver the processes usage still grows. 64031 root 20 0 173m 44m 6652 S 43 2.3 0:09.46 php5 In order to obtain that reading the following was used: before executing: USE_ZEND_ALLOC=0 export USE_ZEND_ALLOC=0 Script: <?php for($i=0;$i<=1000000;$i++){ $m = mysqli_init(); mysqli_real_connect($m,'localhost','root','passwordmysql'); $m = mysqli_close($m); unset($m); if(($i%1000)===0){ echo "Memory consumption after $i iterations is " . memory_get_usage() . "<br /><br />"; flush(); usleep(200); } } die(); ?> and top to obtain the usage ------------------------------------------------------------------------ [2010-03-24 13:56:04] u...@php.net Please also try without Zend nixn...@ulflinux:~/src/php/php-src/branches/PHP_5_3> USE_ZEND_ALLOC=0 sapi/cli/php foo.php Memory consumption after 0 iterations is 8280 Memory consumption after 1000 iterations is 8280 Memory consumption after 2000 iterations is 8280 Memory consumption after 3000 iterations is 8280 Memory consumption after 4000 iterations is 8280 Memory consumption after 5000 iterations is 8280 Memory consumption after 6000 iterations is 8280 Memory consumption after 7000 iterations is 8280 Memory consumption after 8000 iterations is 8280 Memory consumption after 9000 iterations is 8280 Memory consumption after 10000 iterations is 8280 ------------------------------------------------------------------------ [2010-03-23 21:42:14] mat999 at gmail dot com No mysqlnd. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/bug.php?id=51347 -- Edit this bug report at http://bugs.php.net/bug.php?id=51347&edit=1