From dfd32b69fd737658e4546cb2e1c4329b5f74eed3 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 24 Jan 2008 10:49:44 +0000 Subject: [PATCH] Fixed GC bug --- Zend/zend_API.c | 22 +++++++++++----------- Zend/zend_gc.h | 6 ++++++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 0e86be5d7e..07e47ded71 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -3321,7 +3321,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); } @@ -3335,7 +3335,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); } @@ -3350,7 +3350,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); } @@ -3365,7 +3365,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); } @@ -3381,7 +3381,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); if (UG(unicode)) { Z_TYPE_P(property) = IS_UNICODE; Z_USTRVAL_P(property) = malloc(UBYTES(len+1)); @@ -3404,7 +3404,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); if (UG(unicode)) { Z_TYPE_P(property) = IS_UNICODE; Z_USTRVAL_P(property) = malloc(UBYTES(value_len+1)); @@ -3433,7 +3433,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); } @@ -3448,7 +3448,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); } @@ -3463,7 +3463,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); } @@ -3478,7 +3478,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); } @@ -3493,7 +3493,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); if (UG(unicode)) { Z_TYPE_P(constant) = IS_UNICODE; Z_USTRVAL_P(constant) = malloc(UBYTES(value_length+1)); diff --git a/Zend/zend_gc.h b/Zend/zend_gc.h index d6050b03d8..7cf145f989 100644 --- a/Zend/zend_gc.h +++ b/Zend/zend_gc.h @@ -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) \ -- 2.40.0