From:             [EMAIL PROTECTED]
Operating system: Linux
PHP version:      5CVS-2006-08-28 (CVS)
PHP Bug Type:     Scripting Engine problem
Bug description:  leaks in a tricky code with switch() and exceptions

Description:
------------
There are several leaks in the code below.

Reproduce code:
---------------
<?php

function test() {
/* this works
    $type = "apache";
    $l_type = strtolower($type);
    switch(l_$type) {
*/
    $type = "apache";
    switch(strtolower($type)) {
    case "apache":
        throw new Exception("test");
        break;
    }
}

try {
    test();
} catch (Exception $e) {
    echo "the end\n";
}

?>


Expected result:
----------------
.

Actual result:
--------------
[Mon Aug 28 11:48:19 2006]  Script:  '/tmp/1.php'
/local/dev/orig/php-src_5_2/Zend/zend_vm_execute.h(182) :  Freeing
0x4030F19C (16 bytes), script=/tmp/1.php
[Mon Aug 28 11:48:19 2006]  Script:  '/tmp/1.php'
/local/dev/orig/php-src_5_2/Zend/zend_variables.h(45) :  Freeing
0x403113BC (7 bytes), script=/tmp/1.php
/local/dev/orig/php-src_5_2/Zend/zend_variables.c(120) : Actual location
(location was relayed)
=== Total 2 memory leaks detected ===

Valgrind says:

==23114== 7 bytes in 1 blocks are indirectly lost in loss record 1 of 2
==23114==    at 0x401C4CE: malloc (vg_replace_malloc.c:149)
==23114==    by 0x81E5E4B: _emalloc (zend_alloc.c:1628)
==23114==    by 0x81E61E5: _estrndup (zend_alloc.c:1752)
==23114==    by 0x81FDAE7: _zval_copy_ctor_func (zend_variables.c:120)
==23114==    by 0x8180C8D: _zval_copy_ctor (zend_variables.h:45)
==23114==    by 0x8175366: zif_strtolower (string.c:1150)
==23114==    by 0x821D329: zend_do_fcall_common_helper_SPEC
(zend_vm_execute.h:200)
==23114==    by 0x822021C: ZEND_DO_FCALL_SPEC_CONST_HANDLER
(zend_vm_execute.h:1657)
==23114==    by 0x821CF3C: execute (zend_vm_execute.h:92)
==23114==    by 0x821D45E: zend_do_fcall_common_helper_SPEC
(zend_vm_execute.h:234)
==23114==    by 0x822021C: ZEND_DO_FCALL_SPEC_CONST_HANDLER
(zend_vm_execute.h:1657)
==23114==    by 0x821CF3C: execute (zend_vm_execute.h:92)
==23114==    by 0x81FF7D9: zend_execute_scripts (zend.c:1095)
==23114==    by 0x81B8BB2: php_execute_script (main.c:1759)
==23114==    by 0x8264C45: main (php_cli.c:1102)
==23114==
==23114==
==23114== 23 (16 direct, 7 indirect) bytes in 1 blocks are definitely lost
in loss record 2 of 2
==23114==    at 0x401C4CE: malloc (vg_replace_malloc.c:149)
==23114==    by 0x81E5E4B: _emalloc (zend_alloc.c:1628)
==23114==    by 0x821D22B: zend_do_fcall_common_helper_SPEC
(zend_vm_execute.h:182)
==23114==    by 0x822021C: ZEND_DO_FCALL_SPEC_CONST_HANDLER
(zend_vm_execute.h:1657)
==23114==    by 0x821CF3C: execute (zend_vm_execute.h:92)
==23114==    by 0x821D45E: zend_do_fcall_common_helper_SPEC
(zend_vm_execute.h:234)
==23114==    by 0x822021C: ZEND_DO_FCALL_SPEC_CONST_HANDLER
(zend_vm_execute.h:1657)
==23114==    by 0x821CF3C: execute (zend_vm_execute.h:92)
==23114==    by 0x81FF7D9: zend_execute_scripts (zend.c:1095)
==23114==    by 0x81B8BB2: php_execute_script (main.c:1759)
==23114==    by 0x8264C45: main (php_cli.c:1102)


-- 
Edit bug report at http://bugs.php.net/?id=38623&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=38623&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=38623&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=38623&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=38623&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=38623&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=38623&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=38623&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=38623&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=38623&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=38623&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=38623&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=38623&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=38623&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=38623&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=38623&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=38623&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=38623&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=38623&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=38623&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=38623&r=mysqlcfg

Reply via email to