Problem with adding resource as object property

php.internals

Andrey Hristov

23 years ago
Hello, maybe I am doing something wrong but when trying to add a resource (of my type) as property of a object PHP segfaults on shutdown. The code below uses to add the property in the constructor but the result should be the same when the resource is created and added as property in a method. The output while valgrind-ing : Content-type: text/html X-Powered-By: PHP/4.3.3-dev <pre> Done object(someclass)(1) { ["res"]=> resource(1) of type (res check) } ==4514== Jump to the invalid address stated on the next line ==4514== at 0x412EE97C: ??? ==4514== by 0x810C0EB: zend_hash_del_key_or_index (/usr/local/src/php4-STABLE-200306060530/Zend/zend_hash.c:514) ==4514== by 0x810D130: _zend_list_delete (/usr/local/src/php4-STABLE-200306060530/Zend/zend_list.c:56) ==4514== by 0x810795B: _zval_dtor (/usr/local/src/php4-STABLE-200306060530/Zend/zend_variables.c:69) ==4514== Address 0x412EE97C is not stack'd, malloc'd or free'd Segmentation fault res_check.c : #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "php.h" #include "php_ini.h" #include "ext/standard/info.h" #include "php_res_check.h" static int le_res_check; static zend_class_entry *php_some_class_entry_ptr; function_entry res_check_functions[] = { {NULL, NULL, NULL} }; static function_entry php_some_class_functions[] = { PHP_FE(someclass, NULL) {NULL, NULL, NULL} }; zend_module_entry res_check_module_entry = { STANDARD_MODULE_HEADER, "res_check", res_check_functions, PHP_MINIT(res_check), NULL,NULL,NULL,NULL, "0.1", STANDARD_MODULE_PROPERTIES }; /* }}} */ #ifdef COMPILE_DL_RES_CHECK ZEND_GET_MODULE(res_check) #endif static void rsrc_close_res_check(zend_rsrc_list_entry *rsrc TSRMLS_DC) { char *a = (char *) rsrc->ptr; free(a); } PHP_MINIT_FUNCTION(res_check) { zend_class_entry php_some_class_entry; INIT_CLASS_ENTRY(php_some_class_entry, "someclass", php_some_class_functions); php_some_class_entry_ptr = zend_register_internal_class(&php_some_class_entry TSRMLS_CC); le_res_check = zend_register_list_destructors_ex(rsrc_close_res_check, NULL, "res check", 1); return SUCCESS; } PHP_FUNCTION(someclass) { char *a; zval *myself, *res; myself = getThis(); a = (char *) malloc(100); MAKE_STD_ZVAL(res); ZEND_REGISTER_RESOURCE(res, a, le_res_check); add_property_zval_ex(myself, "res", sizeof("res"), res); } ---------------------------------------------------------------- php_res_check.h (standard one) : #ifndef PHP_RES_CHECK_H #define PHP_RES_CHECK_H extern zend_module_entry res_check_module_entry; #define phpext_res_check_ptr &res_check_module_entry #ifdef PHP_WIN32 #define PHP_RES_CHECK_API __declspec(dllexport) #else #define PHP_RES_CHECK_API #endif #ifdef ZTS #include "TSRM.h" #endif PHP_MINIT_FUNCTION(res_check); PHP_FUNCTION(someclass); #endif /* PHP_RES_CHECK_H */ ------------------------------------------------------------------- test.php : <pre> <?php dl('../../../../../../usr/local/src/php4/ext/res_check/modules/res_check.so' ); echo "Done\n\n"; $b = & new someclass(); var_dump($b); ?> Maybe this is a bug, maybe not. Any help or comment is appreciated Thanks, Andrey