Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:2273 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87025 invoked from network); 10 Jun 2003 16:46:02 -0000 Received: from unknown (HELO jedi.webgate.bg) (212.50.2.189) by pb1.pair.com with SMTP; 10 Jun 2003 16:46:02 -0000 Received: from andreywin (nik.office.webgate.bg [192.168.1.22]) by jedi.webgate.bg (8.12.9/8.9.3) with SMTP id h5AGkiQR020940 for ; Tue, 10 Jun 2003 19:46:45 +0300 Message-ID: <001201c32f6f$c763aee0$1601a8c0@andreywin> To: Date: Tue, 10 Jun 2003 19:46:02 +0300 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Subject: Problem with adding resource as object property From: andrey@webgate.bg ("Andrey Hristov") 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
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  :




Maybe this is a bug, maybe not.
Any help or comment is appreciated

Thanks,
Andrey