After 3 days tracing this thing, I found the problem. Any suggestions?
Im trying to define a class constant by allocating a zval str using
ALLOC_ZVAL in PHP_MINIT for my extension. This class constant is applied to
the class and works as expected. The problem comes during shutdown. In
php_request_shutdown --> shutdown_memory_manager, it detects the ZVAL that
the constant was stored in as a "leak" and frees the zval. This causes PHP
to crash during tsrm_shutdown when it starts destroying classes.
Is it expected for a variable allocated during module init to be freed
during request shutdown?
Below is the trace of the class destruction (after the memory manager
already freed my zval in the class_constants ht.
The first line here is freeing the zval associated with the constants key in
the class_entry->constants_table (which has already been freed).
php5ts_debug.dll!_zval_internal_ptr_dtor(_zval_struct * *
php5ts_debug.dll!_zval_internal_ptr_dtor_wrapper(_zval_struct * *
php5ts_debug.dll!zend_hash_destroy(_hashtable * ht=0x009827cc) Line 521 +
php5ts_debug.dll!destroy_zend_class(_zend_class_entry * * pce=0x009e3de4)
php5ts_debug.dll!zend_hash_destroy(_hashtable * ht=0x009e32d8) Line 521 +
php5ts_debug.dll!compiler_globals_dtor(_zend_compiler_globals *
php5ts_debug.dll!tsrm_shutdown() Line 164 + 0x21 C
php.exe!main(int argc=4, char * * argv=0x00902508) Line 1056 + 0x8 C
php.exe!mainCRTStartup() Line 398 + 0x11 C
kernel32.dll!77e814c7()
And here is my the call stack when it frees the memory:
e:\php5\php5cvs\php5\ext\bfl\bfl_system.c(332) : Freeing 0x00920728 (16
bytes), script=test.php
php5ts_debug.dll!shutdown_memory_manager(int silent=0, int full_shutdown=0,
php5ts_debug.dll!php_request_shutdown(void * dummy=0x00000000) Line 1227 +
php.exe!main(int argc=4, char * * argv=0x00902508) Line 1046 + 0xa C
php.exe!mainCRTStartup() Line 398 + 0x11 C
kernel32.dll!77e814c7()
So is it possible to define a class constant during MINIT? If so how. Use a
module global?
Thanks
Bob
Hello Robert,
Tuesday, September 28, 2004, 9:01:00 PM, you wrote:
After 3 days tracing this thing, I found the problem. Any suggestions?
Im trying to define a class constant by allocating a zval str using
ALLOC_ZVAL in PHP_MINIT for my extension.
You cannot use ALLOC_ZVAL during PHP_MINIT.
If you look at zend_declare_property*() you'll find out how to declare your
consts. Maybe we could provide zend_declare_const*() inside the engine.
regards
marcus
This class constant is applied to
the class and works as expected. The problem comes during shutdown. In
php_request_shutdown --> shutdown_memory_manager, it detects the ZVAL that
the constant was stored in as a "leak" and frees the zval. This causes PHP
to crash during tsrm_shutdown when it starts destroying classes.
Is it expected for a variable allocated during module init to be freed
during request shutdown?
Below is the trace of the class destruction (after the memory manager
already freed my zval in the class_constants ht.
The first line here is freeing the zval associated with the constants key in
the class_entry->constants_table (which has already been freed).
php5ts_debug.dll!_zval_internal_ptr_dtor(_zval_struct * *
php5ts_debug.dll!_zval_internal_ptr_dtor_wrapper(_zval_struct * *
php5ts_debug.dll!zend_hash_destroy(_hashtable * ht=0x009827cc) Line 521 +
php5ts_debug.dll!destroy_zend_class(_zend_class_entry * * pce=0x009e3de4)
php5ts_debug.dll!zend_hash_destroy(_hashtable * ht=0x009e32d8) Line 521 +
php5ts_debug.dll!compiler_globals_dtor(_zend_compiler_globals *
php5ts_debug.dll!tsrm_shutdown() Line 164 + 0x21 C
php.exe!main(int argc=4, char * * argv=0x00902508) Line 1056 + 0x8 C
php.exe!mainCRTStartup() Line 398 + 0x11 C
kernel32.dll!77e814c7()
And here is my the call stack when it frees the memory:
e:\php5\php5cvs\php5\ext\bfl\bfl_system.c(332) : Freeing 0x00920728 (16
bytes), script=test.php
php5ts_debug.dll!shutdown_memory_manager(int silent=0, int full_shutdown=0,
php5ts_debug.dll!php_request_shutdown(void * dummy=0x00000000) Line 1227 +
php.exe!main(int argc=4, char * * argv=0x00902508) Line 1046 + 0xa C
php.exe!mainCRTStartup() Line 398 + 0x11 C
kernel32.dll!77e814c7()
So is it possible to define a class constant during MINIT? If so how. Use a
module global?
Thanks
Bob
--
Best regards,
Marcus mailto:helly@php.net