summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@php.net>2008-01-24 10:49:26 +0000
committerDmitry Stogov <dmitry@php.net>2008-01-24 10:49:26 +0000
commit03c018d34eb49019964ba690595f52a2db977584 (patch)
tree52ef8b48d88d4e1e7543a2dc817e2b90151ac913
parent3bd291e11856cebaf48f7b203865e2bffac95200 (diff)
downloadphp-git-03c018d34eb49019964ba690595f52a2db977584.tar.gz
Fixed GC bug
-rw-r--r--Zend/tests/gc_027.phpt12
-rw-r--r--Zend/zend_API.c22
-rw-r--r--Zend/zend_gc.h6
3 files changed, 29 insertions, 11 deletions
diff --git a/Zend/tests/gc_027.phpt b/Zend/tests/gc_027.phpt
new file mode 100644
index 0000000000..9d2418eb4f
--- /dev/null
+++ b/Zend/tests/gc_027.phpt
@@ -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
diff --git a/Zend/zend_API.c b/Zend/zend_API.c
index ca7c16e891..fcf8f2e499 100644
--- a/Zend/zend_API.c
+++ b/Zend/zend_API.c
@@ -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);
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) \