php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67856 Leak when using array_reduce with by-ref function
Submitted: 2014-08-18 14:59 UTC Modified: 2014-08-18 14:59 UTC
From: nikic@php.net Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: master-Git-2014-08-18 (Git) OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: nikic@php.net
New email:
PHP Version: OS:

 

 [2014-08-18 14:59 UTC] nikic@php.net
Description:
------------
Valgrind output:

~/dev/php-src$ ./leak-check.sh t72.php 
==31421== Memcheck, a memory error detector
==31421== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==31421== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==31421== Command: sapi/cli/php t72.php
==31421== 
int(6)
==31421== 
==31421== HEAP SUMMARY:
==31421==     in use at exit: 180 bytes in 7 blocks
==31421==   total heap usage: 14,479 allocs, 14,472 frees, 1,478,806 bytes allocated
==31421== 
==31421== 144 bytes in 6 blocks are definitely lost in loss record 2 of 2
==31421==    at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==31421==    by 0x8440E25: _emalloc (zend_alloc.c:2438)
==31421==    by 0x8468C0B: zend_call_function (zend_execute_API.c:815)
==31421==    by 0x8333833: zif_array_reduce (array.c:4305)
==31421==    by 0x84C39BC: ZEND_DO_FCALL_SPEC_HANDLER (zend_vm_execute.h:595)
==31421==    by 0x84C2D16: execute_ex (zend_vm_execute.h:354)
==31421==    by 0x84C2ECA: zend_execute (zend_vm_execute.h:383)
==31421==    by 0x847FC4F: zend_execute_scripts (zend.c:1319)
==31421==    by 0x83D9C4C: php_execute_script (main.c:2564)
==31421==    by 0x852CE63: do_cli (php_cli.c:980)
==31421==    by 0x852E217: main (php_cli.c:1358)
==31421== 
==31421== LEAK SUMMARY:
==31421==    definitely lost: 144 bytes in 6 blocks
==31421==    indirectly lost: 0 bytes in 0 blocks
==31421==      possibly lost: 0 bytes in 0 blocks
==31421==    still reachable: 36 bytes in 1 blocks
==31421==         suppressed: 0 bytes in 0 blocks
==31421== Reachable blocks (those to which a pointer was found) are not shown.
==31421== To see them, rerun with: --leak-check=full --show-reachable=yes
==31421== 
==31421== For counts of detected and suppressed errors, rerun with: -v
==31421== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)


Test script:
---------------
<?php
$array = [1, 2, 3];
var_dump(array_reduce($array, function(&$a, &$b) {
    return $a + $b;
}, 0));


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-18 14:59 UTC] nikic@php.net
-Assigned To: +Assigned To: dmitry
 [2014-08-18 17:10 UTC] dmitry@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=0f5bad93fd9eb0bb73855b536d15c6b6bacb6dbc
Log: Fixed bug #67856 (Leak when using array_reduce with by-ref function)
 [2014-08-18 17:10 UTC] dmitry@php.net
-Status: Assigned +Status: Closed
 [2016-07-20 11:40 UTC] davey@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=0f5bad93fd9eb0bb73855b536d15c6b6bacb6dbc
Log: Fixed bug #67856 (Leak when using array_reduce with by-ref function)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 15:01:36 2025 UTC