|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-02-03 01:19 UTC] danger at FreeBSD dot org
Description: ------------ The strtotime() function still leaks memory in patched PHP 5.2.8 after applying patches from http://news.php.net/php.cvs/55000. The memory leak itself is much smaller than before applying fixes. Before, it took a few seconds to leak 1gb of mem, now it takes some minutes however it's still there. This bug is related to http://bugs.php.net/bug.php?id=46889. Reproduce code: --------------- while (true) { $tmp = inc_stamp(time(), 1); } function inc_stamp($timestamp, $off_days) { return strtotime("+" . $off_days . " day", $timestamp); } Actual result: -------------- Memory leak reported by top(1). If the script runs for longer time, it gets killed by kernel since the system is going out of memory and swap. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 22:00:02 2025 UTC |
root@[web1 ~]# php -v PHP 5.2.9-dev (cli) (built: Feb 5 2009 10:52:28) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies with XCache v1.2.2, Copyright (c) 2005-2007, by mOo I also applied distribution patches that come with FreeBSD (exluding the patch-ext_date_lib_timelib_structs.h one), you may find them at http://cvsweb.freebsd.org/ports/lang/php5/files. Verified that the above PHP version still leaks memory, slower but still.I have the same problem: PHP 5.2.9RC2-dev (cli) (built: Feb 12 2009 15:10:25) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies On FreeBSD 6.3. Built PHP without FreeBSD patches, just downloaded latest and did "cd php5.2-200902121330", "./configure", "make" and "./sapi/cli/php" <?php while (1) { $a=strtotime ( 'now', time() ); } Top shows the memory usage growing steadily.Leak also observed in 5.2.8 and 5.2.9 on Linux. This patch (against 5.2.9) is working out for us so far in our dev environment: --- ext/date/php_date.orig.c 2009-03-11 10:07:36.000000000 -0500 +++ ext/date/php_date.c 2009-03-11 10:12:40.000000000 -0500 @@ -1108,7 +1108,7 @@ long preset_ts, ts; timelib_time *t, *now; - timelib_tzinfo *tzi; + timelib_tzinfo *tzi, *old_tzi; tzi = get_timezone_info(TSRMLS_C); @@ -1119,10 +1119,14 @@ initial_ts = emalloc(25); snprintf(initial_ts, 24, "@%ld UTC", preset_ts); t = timelib_strtotime(initial_ts, strlen(initial_ts), NULL, DATE_TIMEZONEDB); /* we ignore the error here, as this should never fail */ + old_tzi = t->tz_info; timelib_update_ts(t, tzi); now->tz_info = tzi; now->zone_type = TIMELIB_ZONETYPE_ID; timelib_unixtime2local(now, t->sse); + if ( old_tzi ) { + timelib_tzinfo_dtor(old_tzi); + } timelib_time_dtor(t); efree(initial_ts); } else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", ×, &time_len, &preset_ts) != FAILURE) { @@ -1141,6 +1145,7 @@ } t = timelib_strtotime(times, time_len, &error, DATE_TIMEZONEDB); + old_tzi = t->tz_info; error1 = error->error_count; timelib_error_container_dtor(error); timelib_fill_holes(t, now, TIMELIB_NO_CLONE); @@ -1148,6 +1153,9 @@ ts = timelib_date_to_int(t, &error2); timelib_time_dtor(now); + if ( old_tzi ) { + timelib_tzinfo_dtor(old_tzi); + } timelib_time_dtor(t); if (error1 || error2) {Reproduced on RHEL 4 (PHP built from source not RPM) PHP 5.2.9 (cli) (built: May 1 2009 13:47:24) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies with Zend Debugger v5.2.14, Copyright (c) 1999-2008, by Zend Technologies Applying the patch from oliver at realtsp dot com slowed down the leak, but did not stop it entirely.Problem verified on: Linux version 2.6.30-1-amd64 (Debian 2.6.30-6) (waldi@debian.org) (gcc version 4.3.4 (Debian 4.3.4-1) ) #1 SMP Sat Aug 15 21:08:31 UTC 2009 Using: PHP 5.2.10-2 with Suhosin-Patch 0.9.7 (cli) (built: Jul 10 2009 00:34:06) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies with Suhosin v0.9.28, Copyright (c) 2007, by SektionEins GmbHI've built PHP 5.2 from SVN (r.296066) from scratch on vanilla Debian Lenny and ran valgrind on this problem. Here is the output: $ valgrind --leak-check=full ./sapi/cli/php -n -r 'strtotime("now",time());' ==21329== Memcheck, a memory error detector. ==21329== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al. ==21329== Using LibVEX rev 1854, a library for dynamic binary translation. ==21329== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP. ==21329== Using valgrind-3.3.1-Debian, a dynamic binary instrumentation framework. ==21329== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al. ==21329== For more details, rerun with: -v ==21329== ==21329== ==21329== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 27 from 1) ==21329== malloc/free: in use at exit: 76 bytes in 4 blocks. ==21329== malloc/free: 7,796 allocs, 7,792 frees, 1,305,337 bytes allocated. ==21329== For counts of detected errors, rerun with: -v ==21329== searching for pointers to 4 not-freed blocks. ==21329== checked 429,556 bytes. ==21329== ==21329== 76 (48 direct, 28 indirect) bytes in 1 blocks are definitely lost in loss record 4 of 4 ==21329== at 0x4021E22: calloc (vg_replace_malloc.c:397) ==21329== by 0x809DDAA: timelib_tzinfo_ctor (timelib.c:75) ==21329== by 0x809D0F7: timelib_parse_tzfile (parse_tz.c:277) ==21329== by 0x8084211: timelib_get_zone (parse_date.re:737) ==21329== by 0x8085859: timelib_strtotime (parse_date.re:1007) ==21329== by 0x8080A4C: zif_strtotime (php_date.c:1143) ==21329== by 0x8284379: zend_do_fcall_common_helper_SPEC (zend_vm_execute.h:200) ==21329== by 0x82710AF: execute (zend_vm_execute.h:92) ==21329== by 0x8243A26: zend_eval_string (zend_execute_API.c:1223) ==21329== by 0x8243B7E: zend_eval_string_ex (zend_execute_API.c:1258) ==21329== by 0x82BCC29: main (php_cli.c:1204) ==21329== ==21329== LEAK SUMMARY: ==21329== definitely lost: 48 bytes in 1 blocks. ==21329== indirectly lost: 28 bytes in 3 blocks. ==21329== possibly lost: 0 bytes in 0 blocks. ==21329== still reachable: 0 bytes in 0 blocks. ==21329== suppressed: 0 bytes in 0 blocks. Please let me know if there is any more I can do, next to fixing the bug obviously... :-) I'm looking in to that...I've just ran maartens valgrind repro on most recent PHP 5.6 and master on Debian Jessie: All heap blocks were freed -- no leaks are possible Furthermore I've ran the OP's test script on Windows 7 with most recent PHP 5.6 and master, and I can't detect any memory leaks. So apparently this issue has been resolved – closing.