Jelajahi Sumber

Fixed script destructor and free resource struct when done.

Taneli Leppa 11 tahun lalu
induk
melakukan
200c16c30e
2 mengubah file dengan 12 tambahan dan 6 penghapusan
  1. 1 1
      php_v8js_macros.h
  2. 11 5
      v8js.cc

+ 1 - 1
php_v8js_macros.h

@@ -292,7 +292,7 @@ typedef struct _php_v8js_script {
 	v8::Persistent<v8::Script, v8::CopyablePersistentTraits<v8::Script>> *script;
 } php_v8js_script;
 
-static void php_v8js_script_free(php_v8js_script *res);
+static void php_v8js_script_free(php_v8js_script *res, bool dispose_persistent);
 
 #endif	/* PHP_V8JS_MACROS_H */
 

+ 11 - 5
v8js.cc

@@ -1316,7 +1316,7 @@ static PHP_METHOD(V8Js, executeString)
 		RETURN_FALSE;
 	}
 	php_v8js_execute_script(getThis(), res, flags, time_limit, memory_limit, &return_value);
-	php_v8js_script_free(res);
+	php_v8js_script_free(res, true);
 
 }
 /* }}} */
@@ -1521,19 +1521,25 @@ static void php_v8js_persistent_zval_dtor(zval **p) /* {{{ */
 }
 /* }}} */
 
-static void php_v8js_script_free(php_v8js_script *res)
+static void php_v8js_script_free(php_v8js_script *res, bool dispose_persistent)
 {
 	if (res->name) {
 		efree(res->name);
+		res->name = NULL;
+	}
+	if (dispose_persistent) {
+		res->script->~Persistent(); // does Reset()
+		res->script = NULL;
 	}
-	res->script->Reset();
-	res->script->~Persistent();
 }
 
 static void php_v8js_script_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */
 {
 	php_v8js_script *res = (php_v8js_script *)rsrc->ptr;
-	if (res) php_v8js_script_free(res);
+	if (res) {
+		php_v8js_script_free(res, false);
+		efree(res);
+	}
 }
 /* }}} */