From:             
Operating system: linux
PHP version:      5.4.0
Package:          *Compile Issues
Bug Type:         Bug
Bug description:insteadof cause memory leak if class is not binded

Description:
------------
when class is not binded, "insteadof" cause a detected memory leak. see the

following script and output

==============
after days tracking, i lock on _destroy_zend_class_traits_info
    if (ce->trait_precedences) {
        size_t i = 0;

        while (ce->trait_precedences[i]) {
           
efree((char*)ce->trait_precedences[i]->trait_method->method_name);
           
efree((char*)ce->trait_precedences[i]->trait_method->class_name);
            efree(ce->trait_precedences[i]->trait_method);

            if (ce->trait_precedences[i]->exclude_from_classes) {
                efree(ce->trait_precedences[i]->exclude_from_classes);  <-

before this line
            }

ce->trait_precedences[i]->exclude_from_classes[0] is string, should but not

efree'ed, this is why it's leaking. however when the class is bind, it is 
zend_class_entry and should not efree 

Test script:
---------------
<?php
if (0) {
        class A {
                use b2, b33 {
                        b2::b444 insteadof b33;
                        b2::b444 as b5555;
                }
        }
}


Expected result:
----------------
./php-cgi -c php.ini test.php
X-Powered-By: PHP/5.4.1RC1-dev
Content-type: text/html



Actual result:
--------------
./php-cgi -c php.ini test.php
X-Powered-By: PHP/5.4.1RC1-dev
Content-type: text/html

[Mon Mar 26 13:40:12 2012]  Script:  'ZZZZZZZZZZs|▒▒▒▒'▒]▒G'
Zend/zend_language_scanner.l(1889) :  Freeing 0x7F4720728688 (4 bytes), 
script=ZZZZZZZZZZs|▒▒▒▒'▒]▒G
=== Total 1 memory leaks detected ===

valgrind outputs:

==31399== 4 bytes in 1 blocks are definitely lost in loss record 1 of 84
==31399==    at 0x4C2879E: malloc (in
/usr/lib64/valgrind/vgpreload_memcheck-
amd64-linux.so)
==31399==    by 0x8E9C41: _emalloc (zend_alloc.c:2423)
==31399==    by 0x8EA1A6: _estrndup (zend_alloc.c:2596)
==31399==    by 0x8D050E: lex_scan (zend_language_scanner.l:1889)
==31399==    by 0x905A52: zendlex (zend_compile.c:6666)
==31399==    by 0x8C5F45: zendparse (zend_language_parser.c:3099)
==31399==    by 0x8CC630: compile_file (zend_language_scanner.l:579)
==31399==    by 0x6F2C45: phar_compile_file (phar.c:3391)
==31399==    by 0x91F846: zend_execute_scripts (zend.c:1265)
==31399==    by 0x896FEC: php_execute_script (main.c:2473)
==31399==    by 0xA6D136: main (cgi_main.c:2422)


-- 
Edit bug report at https://bugs.php.net/bug.php?id=61506&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=61506&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=61506&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=61506&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=61506&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=61506&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=61506&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=61506&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=61506&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=61506&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=61506&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=61506&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=61506&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=61506&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=61506&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=61506&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=61506&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=61506&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=61506&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=61506&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=61506&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=61506&r=mysqlcfg

Reply via email to