]> granicus.if.org Git - php/commitdiff
Fixed GC bug
authorDmitry Stogov <dmitry@php.net>
Thu, 24 Jan 2008 10:49:26 +0000 (10:49 +0000)
committerDmitry Stogov <dmitry@php.net>
Thu, 24 Jan 2008 10:49:26 +0000 (10:49 +0000)
Zend/tests/gc_027.phpt [new file with mode: 0644]
Zend/zend_API.c
Zend/zend_gc.h

diff --git a/Zend/tests/gc_027.phpt b/Zend/tests/gc_027.phpt
new file mode 100644 (file)
index 0000000..9d2418e
--- /dev/null
@@ -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
index ca7c16e8910f1c1d1d93fdd88f4f92db3abe69c0..fcf8f2e499a2f3f42e8276f9c04d6d8fb3842134 100644 (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);
index d6050b03d8744f499781cd4f5fe3585b941bc271..7cf145f989a8c07255382ce326e25d26841341e0 100644 (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)                                                                  \