PHP 4.0.3 patches - resources
| From: | (Mikhail Zabaluev) | Date: | Fri, 03 Nov 2000 06:20:13 +0000 |
| Subject: | PHP 4.0.3 patches - resources | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-36911@lists.php.net to get a copy of this message | ||
Hello, PHP developers.
I made two fixes on PHP 4.0.3pl1 in order for it to work out my needs.
One patch comes in this message, another follows in the next one.
The first patch tries to fix resource deallocation problem in case of an
aggregation loop, such as when we bind an object to a parser resource with
xml_parser_set_object(), and the object contains that parser as a
property. I got a segfault every time after a response was sent, and found
out that a parser resource is being recursively destroyed twice!
Setting reference counts for resource entries to 0 prior to destruction
of the global resource lists seems to fix this.
--
Stay tuned,
MhZ mailto:mookid@sigent.ru
-----------
travel, n.:
Something that makes you feel like you're getting somewhere.
--- Zend/zend_list.c~ Thu Nov 2 15:32:09 2000 +++ Zend/zend_list.c Thu Nov 2 20:03:23 2000 @@ -55,7 +55,7 @@ if (zend_hash_index_find(&EG(regular_list), id, (void **) &le)==SUCCESS) { /* printf("del(%d): %d->%d\n", id, le->refcount, le->refcount-1); */ - if (--le->refcount<=0) { + if (--le->refcount == 0) { return zend_hash_index_del(&EG(regular_list), id); } else { return SUCCESS; @@ -293,15 +293,25 @@ } +static int destroy_resource_entry(zend_rsrc_list_entry *le) { + le->refcount = 0; + return 1; +} + + void zend_destroy_rsrc_list(ELS_D) { - zend_hash_graceful_destroy(&EG(regular_list)); + HashTable* pl = &EG(regular_list); + zend_hash_apply(pl, (apply_func_t)destroy_resource_entry); + zend_hash_destroy(pl); } void zend_destroy_rsrc_plist(ELS_D) { - zend_hash_graceful_destroy(&EG(persistent_list)); + HashTable* pl = &EG(persistent_list); + zend_hash_apply(pl, (apply_func_t)destroy_resource_entry); + zend_hash_destroy(pl); }
--- Zend/zend_list.c~ Thu Nov 2 15:32:09 2000 +++ Zend/zend_list.c Thu Nov 2 20:03:23 2000 @@ -55,7 +55,7 @@ if (zend_hash_index_find(&EG(regular_list), id, (void **) &le)==SUCCESS) { /* printf("del(%d): %d->%d\n", id, le->refcount, le->refcount-1); */ - if (--le->refcount<=0) { + if (--le->refcount == 0) { return zend_hash_index_del(&EG(regular_list), id); } else { return SUCCESS; @@ -293,15 +293,25 @@ } +static int destroy_resource_entry(zend_rsrc_list_entry *le) { + le->refcount = 0; + return 1; +} + + void zend_destroy_rsrc_list(ELS_D) { - zend_hash_graceful_destroy(&EG(regular_list)); + HashTable* pl = &EG(regular_list); + zend_hash_apply(pl, (apply_func_t)destroy_resource_entry); + zend_hash_destroy(pl); } void zend_destroy_rsrc_plist(ELS_D) { - zend_hash_graceful_destroy(&EG(persistent_list)); + HashTable* pl = &EG(persistent_list); + zend_hash_apply(pl, (apply_func_t)destroy_resource_entry); + zend_hash_destroy(pl); }