Changeset 92

Show
Ignore:
Timestamp:
05/10/05 20:46:29 (3 years ago)
Author:
zoeloelip
Message:

Final fix for the properties_info memleak/segfault, it uses a trick to steal the
pointer from the static destructor function in the zendengine. Thanks to hoesh for his
help!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • eaccelerator/trunk/eaccelerator.c

    r90 r92  
    115115 
    116116FILE *F_fp; 
     117 
     118/* pointer to the properties_info hashtable destructor */ 
     119static dtor_func_t properties_info_dtor = NULL; 
    117120 
    118121/* saved original functions */ 
     
    23912394} 
    23922395 
    2393 /* is equal to zend_destroy_property_info in zend_compile.c, this function is  
    2394  * needed as destructor for the properties_info hashtable, but is declared  
    2395  * static, so redefine it here. */ 
    2396 static void destroy_property_info(zend_property_info *property_info) { 
    2397   efree(property_info->name); 
    2398 } 
    2399  
    24002396static zend_class_entry* restore_class_entry(zend_class_entry* to, eaccelerator_class_entry *from TSRMLS_DC) 
    24012397{ 
     
    25362532  to->default_properties.pDestructor = ZVAL_PTR_DTOR; 
    25372533  restore_hash(&to->properties_info, &from->properties_info, (restore_bucket_t)restore_property_info TSRMLS_CC); 
    2538   to->properties_info.pDestructor = (dtor_func_t) destroy_property_info
     2534  to->properties_info.pDestructor = properties_info_dtor
    25392535  if (from->static_members != NULL) { 
    25402536    ALLOC_HASHTABLE(to->static_members); 
     
    37443740} 
    37453741 
     3742/* This function creates a dummy class entry to steal the pointer to the  
     3743 * properties_info hashtable destructor because it's declared static */ 
     3744static dtor_func_t get_zend_destroy_property_info(TSRMLS_D) { 
     3745  zend_class_entry dummy_class_entry; 
     3746  dummy_class_entry.type = ZEND_USER_CLASS;  
     3747 
     3748  zend_initialize_class_data(&dummy_class_entry, 1 TSRMLS_CC);  
     3749 
     3750  dtor_func_t property_dtor = dummy_class_entry.properties_info.pDestructor; 
     3751 
     3752  zend_hash_destroy(&dummy_class_entry.default_properties); 
     3753  zend_hash_destroy(&dummy_class_entry.properties_info); 
     3754  zend_hash_destroy(dummy_class_entry.static_members); 
     3755  zend_hash_destroy(&dummy_class_entry.function_table); 
     3756  FREE_HASHTABLE(dummy_class_entry.static_members); 
     3757  zend_hash_destroy(&dummy_class_entry.constants_table); 
     3758   
     3759  return property_dtor; 
     3760} 
     3761 
    37463762PHP_MINIT_FUNCTION(eaccelerator) { 
    37473763  if (type == MODULE_PERSISTENT) { 
     
    38323848    register_eaccelerator_as_zend_extension(); 
    38333849  } 
     3850   
     3851  /* cache the properties_info destructor */ 
     3852  properties_info_dtor = get_zend_destroy_property_info(TSRMLS_C); 
     3853   
    38343854  return SUCCESS; 
    38353855}