php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45047 memory leak with array as default function parameter in encoded code
Submitted: 2008-05-20 08:38 UTC Modified: 2008-05-21 22:15 UTC
Votes:4
Avg. Score:4.8 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:4 (100.0%)
Same OS:4 (100.0%)
From: lars_teuber at gmx dot de Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: 5.2.6 OS: linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: lars_teuber at gmx dot de
New email:
PHP Version: OS:

 

 [2008-05-20 08:38 UTC] lars_teuber at gmx dot de
Description:
------------
memory leak with array as default function parameter in encoded code

- code encoded by Zend Guard 5.0.1
- tested on linux, apache with php 5.2.5 and php 5.2.6
- not reproducible under Windows (IIS, php 5.2.6 or Apache, php 5.2.5)
- not reproducible with unencoded code
- memory leak occurs only under linux with Zend encoded code

Reproduce code:
---------------
<?php
$max = 1000000;

// this leaks if the code is encoded
$start_mem = memory_get_usage(true);
for ($i = 0; $i < $max; $i++) {
    leak();
}
echo 'leak mem1: [' . (memory_get_usage(true) - $start_mem) . "]\n<br>";

// this does not leak
$start_mem = memory_get_usage(true);
for ($i = 0; $i < $max; $i++) {
    leak(array($i));
}
echo 'leak mem2: [' . (memory_get_usage(true) - $start_mem) . ']';

function leak($leak = array()) {}
?>

Expected result:
----------------
leak mem1: [0]
leak mem2: [0]

Actual result:
--------------
leak mem1: [87818240]
leak mem2: [0] 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-05-21 22:10 UTC] crrodriguez at suse dot de
Do not file bugs when you have Zend extensions (zend_extension=)
loaded. Examples are Zend Optimizer, Zend Debugger, Turck MM Cache,
APC, Xdebug and ionCube loader.  These extensions often modify engine
behavior which is not related to PHP itself.
 [2008-05-21 22:15 UTC] felipe@php.net
.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 20 03:00:03 2025 UTC