Edit report at http://bugs.php.net/bug.php?id=51760&edit=1

 ID:               51760
 Updated by:       tony2...@php.net
 Reported by:      russell dot tempero at rightnow dot com
 Summary:          Memory Leak: zend hash not properly destroyed in CGI
                   main
-Status:           Open
+Status:           Feedback
 Type:             Bug
 Package:          Performance problem
 Operating System: Linux
 PHP Version:      5.3.2

 New Comment:

This hash is destroyed on shutdown by this function:

static PHP_MSHUTDOWN_FUNCTION(cgi)

{

    zend_hash_destroy(&CGIG(user_config_cache));



    UNREGISTER_INI_ENTRIES();

    return SUCCESS;

}


Previous Comments:
------------------------------------------------------------------------
[2010-05-14 20:32:47] russell dot tempero at rightnow dot com

In my patch I forgot to set ht->pListHead to NULL. The following line
should be added toward the end of the zend_hash_destroy() function:



ht->pListHead = NULL;

------------------------------------------------------------------------
[2010-05-06 23:57:27] russell dot tempero at rightnow dot com

Description:
------------
After upgrading to PHP 5.3.2, we ran it through Purify and noticed the
following memory leak:



MLK: 32 bytes leaked at 0x9b70ca8

  * This memory was allocated from:

    calloc         [rtlib.o]

    _zend_hash_init [zend_hash.c:168]

    php_cgi_globals_ctor [cgi_main.c:1429]

    allocate_new_resource [TSRM.c:303]

    ts_resource_ex [TSRM.c:370]

    .

    .

    .



The problem is that php_cgi_globals_ctor() (the constructor) is calling
zend_hash_init() but there is no corresponding destructor to call
zend_hash_destroy(). I have attached a patch that will fix this.



You will notice in the patch that I had to make changes to
zend_hash_destroy() to prevent a double free. Apparently there are
places that are already calling zend_hash_destroy() for the hash that is
initialized in php_cgi_globals_ctor(), but it is not currently getting
called all of the time. Perhaps a more correct fix would be to find
where these other calls to zend_hash_destroy() are being made and either
eliminate them altogether or make sure they are called all of the time
and not have the destructor function.



------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=51760&edit=1

Reply via email to