Fixed GC bug

This commit is contained in:
Dmitry Stogov 2008-01-24 10:49:26 +00:00
parent 3bd291e118
commit 03c018d34e
3 changed files with 29 additions and 11 deletions

12
Zend/tests/gc_027.phpt Normal file
View File

@ -0,0 +1,12 @@
--TEST--
GC 027: GC and properties of internal classes
--FILE--
<?php
try {
throw new Exception();
} catch (Exception $e) {
gc_collect_cycles();
}
echo "ok\n";
--EXPECT--
ok

View File

@ -2850,7 +2850,7 @@ ZEND_API int zend_declare_property_null(zend_class_entry *ce, char *name, int na
zval *property;
if (ce->type & ZEND_INTERNAL_CLASS) {
property = malloc(sizeof(zval));
ALLOC_PERMANENT_ZVAL(property);
} else {
ALLOC_ZVAL(property);
}
@ -2864,7 +2864,7 @@ ZEND_API int zend_declare_property_bool(zend_class_entry *ce, char *name, int na
zval *property;
if (ce->type & ZEND_INTERNAL_CLASS) {
property = malloc(sizeof(zval));
ALLOC_PERMANENT_ZVAL(property);
} else {
ALLOC_ZVAL(property);
}
@ -2879,7 +2879,7 @@ ZEND_API int zend_declare_property_long(zend_class_entry *ce, char *name, int na
zval *property;
if (ce->type & ZEND_INTERNAL_CLASS) {
property = malloc(sizeof(zval));
ALLOC_PERMANENT_ZVAL(property);
} else {
ALLOC_ZVAL(property);
}
@ -2894,7 +2894,7 @@ ZEND_API int zend_declare_property_double(zend_class_entry *ce, char *name, int
zval *property;
if (ce->type & ZEND_INTERNAL_CLASS) {
property = malloc(sizeof(zval));
ALLOC_PERMANENT_ZVAL(property);
} else {
ALLOC_ZVAL(property);
}
@ -2910,7 +2910,7 @@ ZEND_API int zend_declare_property_string(zend_class_entry *ce, char *name, int
int len = strlen(value);
if (ce->type & ZEND_INTERNAL_CLASS) {
property = malloc(sizeof(zval));
ALLOC_PERMANENT_ZVAL(property);
ZVAL_STRINGL(property, zend_strndup(value, len), len, 0);
} else {
ALLOC_ZVAL(property);
@ -2926,7 +2926,7 @@ ZEND_API int zend_declare_property_stringl(zend_class_entry *ce, char *name, int
zval *property;
if (ce->type & ZEND_INTERNAL_CLASS) {
property = malloc(sizeof(zval));
ALLOC_PERMANENT_ZVAL(property);
ZVAL_STRINGL(property, zend_strndup(value, value_len), value_len, 0);
} else {
ALLOC_ZVAL(property);
@ -2948,7 +2948,7 @@ ZEND_API int zend_declare_class_constant_null(zend_class_entry *ce, char *name,
zval *constant;
if (ce->type & ZEND_INTERNAL_CLASS) {
constant = malloc(sizeof(zval));
ALLOC_PERMANENT_ZVAL(constant);
} else {
ALLOC_ZVAL(constant);
}
@ -2963,7 +2963,7 @@ ZEND_API int zend_declare_class_constant_long(zend_class_entry *ce, char *name,
zval *constant;
if (ce->type & ZEND_INTERNAL_CLASS) {
constant = malloc(sizeof(zval));
ALLOC_PERMANENT_ZVAL(constant);
} else {
ALLOC_ZVAL(constant);
}
@ -2978,7 +2978,7 @@ ZEND_API int zend_declare_class_constant_bool(zend_class_entry *ce, char *name,
zval *constant;
if (ce->type & ZEND_INTERNAL_CLASS) {
constant = malloc(sizeof(zval));
ALLOC_PERMANENT_ZVAL(constant);
} else {
ALLOC_ZVAL(constant);
}
@ -2993,7 +2993,7 @@ ZEND_API int zend_declare_class_constant_double(zend_class_entry *ce, char *name
zval *constant;
if (ce->type & ZEND_INTERNAL_CLASS) {
constant = malloc(sizeof(zval));
ALLOC_PERMANENT_ZVAL(constant);
} else {
ALLOC_ZVAL(constant);
}
@ -3008,7 +3008,7 @@ ZEND_API int zend_declare_class_constant_stringl(zend_class_entry *ce, char *nam
zval *constant;
if (ce->type & ZEND_INTERNAL_CLASS) {
constant = malloc(sizeof(zval));
ALLOC_PERMANENT_ZVAL(constant);
ZVAL_STRINGL(constant, zend_strndup(value, value_length), value_length, 0);
} else {
ALLOC_ZVAL(constant);

View File

@ -199,6 +199,12 @@ static zend_always_inline void gc_remove_zval_from_buffer(zval* z)
}
}
#define ALLOC_PERMANENT_ZVAL(z) \
do { \
(z) = (zval*)malloc(sizeof(zval_gc_info)); \
GC_ZVAL_INIT(z); \
} while (0)
/* The following macroses override macroses from zend_alloc.h */
#undef ALLOC_ZVAL
#define ALLOC_ZVAL(z) \