我在Linux上运行PHP 5.4.0。
这是ZEND_MINIT_FUNCTION中的代码
#ifdef ZTS
ts_allocate_id( &sample_globals_id,
sizeof(zend_sample_globals),
(ts_allocate_ctor) php_sample_init_globals,
(ts_allocate_dtor) php_sample_destroy_globals);
#else
php_sample_init_globals(& sample_globals TSRMLS_CC);
#endif
当模块完成其 MSHUTDOWN 时,此代码崩溃。GDB 指向 TSRM.c ,此行(调用 dtor):
if (p->storage[j]) {
if (resource_types_table && !resource_types_table[j].done && resource_types_table[j].dtor) {
resource_types_table[j].dtor(p->storage[j], &p->storage);
}
free(p->storage[j]);
}
更奇怪的是,当我用 NULL 替换析构函数时,它可以工作。喜欢这个:
ts_allocate_id( &sample_globals_id,
sizeof(zend_sample_globals),
(ts_allocate_ctor) php_sample_init_globals,
NULL ); //Works, but destructor is not called
也许有人知道为什么会发生这种情况?谢谢
找到了。奇怪的是,这在任何教程中都没有描述,但答案在于 ext 目录中的源代码。
我已将下一个代码添加到 MSHUTDOWN
#ifdef ZTS
ts_free_id(sample_globals_id);
#endif
现在它工作正常。噗......