]> granicus.if.org Git - php/commitdiff
- Flag ctor/dtor methods
authorMarcus Boerger <helly@php.net>
Sat, 23 Aug 2003 15:38:58 +0000 (15:38 +0000)
committerMarcus Boerger <helly@php.net>
Sat, 23 Aug 2003 15:38:58 +0000 (15:38 +0000)
- Use this to prevent memleaks when an exception gets thrown in ctors.
# I added the dtor flags for consistency, atm a compareable check in
# isn't necessary for destruction. But anyway i'll use this for the
# Relection API too.

Zend/zend_API.c
Zend/zend_compile.c
Zend/zend_compile.h
Zend/zend_execute.c

index ac459028d837172ef1ae2fca45ccc0b68ae07053..7d5745b4f70238c2445ca0018be96fde07f63a28 100644 (file)
@@ -1241,6 +1241,12 @@ int zend_register_functions(zend_class_entry *scope, zend_function_entry *functi
                scope->constructor = ctor;
                scope->destructor = dtor;
                scope->clone = clone;
+               if (ctor) {
+                       ctor->common.fn_flags |= ZEND_ACC_CTOR;
+               }
+               if (dtor) {
+                       dtor->common.fn_flags |= ZEND_ACC_DTOR;
+               }
        }
        return SUCCESS;
 }
index 9403cafa6bec50baab25a70bfc5d2badeb51aedc..b119b0a230042ff0efa42a872404d30ecd4a17e6 100644 (file)
@@ -2252,6 +2252,13 @@ void zend_do_end_class_declaration(znode *class_token, znode *parent_token TSRML
 
        do_inherit_parent_constructor(ce);
 
+       if (ce->constructor) {
+               ce->constructor->common.fn_flags |= ZEND_ACC_CTOR;
+       }
+       if (ce->destructor) {
+               ce->destructor->common.fn_flags |= ZEND_ACC_DTOR;
+       }
+
        ce->line_end = zend_get_compiled_lineno(TSRMLS_C);
 
        /* Inherit interfaces */
index 9cb30999fade3b8bea35d322ef718cf1b5c5682b..21014202a58ca17d38b17d6c1812a014ee414aa5 100644 (file)
@@ -110,6 +110,9 @@ typedef struct _zend_brk_cont_element {
 #define ZEND_ACC_CHANGED       0x800
 #define ZEND_ACC_IMPLICIT_PUBLIC       0x1000
 
+#define ZEND_ACC_CTOR          0x2000
+#define ZEND_ACC_DTOR          0x4000
+
 char *zend_visibility_string(zend_uint fn_flags);
 
 
index a9a7a9328f0e0b38de31b4c99f816d6e75d2356b..aaf5b427e7bbedc4466248ee9c7aa4ff1b6e03ee 100644 (file)
@@ -2610,10 +2610,16 @@ int zend_do_fcall_common_helper(ZEND_OPCODE_HANDLER_ARGS)
                }
        }
 
-       if (should_change_scope) {
-               if (EG(This)) {
+       if (EG(This)) {
+               if (EG(exception) && EX(fbc)->common.fn_flags&ZEND_ACC_CTOR) {
+                       EG(This)->refcount = 1;
+                       zval_ptr_dtor(&EG(This));
+               } else if (should_change_scope) {
                        zval_ptr_dtor(&EG(This));
                }
+       }
+
+       if (should_change_scope) {
                EG(This) = current_this;
                EG(scope) = current_scope;
        }