- 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.
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;
}
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 */
#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);
}
}
- 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;
}