Skip to content
This repository was archived by the owner on Mar 29, 2024. It is now read-only.

Commit cc9ffd5

Browse files
committed
Fix segfaults on unclean shutdown
1 parent a2781b1 commit cc9ffd5

7 files changed

+10
-9
lines changed

Diff for: php_v8.h

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ ZEND_END_MODULE_GLOBALS(v8)
7575
#define zend_get_executed_scope() EG(scope)
7676
#endif
7777

78+
#define PHP_V8_IS_UP_AND_RUNNING() (zend_is_executing() && !CG(unclean_shutdown))
7879

7980
/* Always refer to the globals in your function as PHP_V8_G(variable).
8081
You are encouraged to rename these macros something shorter, see

Diff for: src/php_v8_context.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static void php_v8_context_free(zend_object *object)
3131
php_v8_context_t *php_v8_context = php_v8_context_fetch_object(object);
3232

3333
if (php_v8_context->context) {
34-
if (PHP_V8_ISOLATE_HAS_VALID_HANDLE(php_v8_context)) {
34+
if (PHP_V8_IS_UP_AND_RUNNING() && PHP_V8_ISOLATE_HAS_VALID_HANDLE(php_v8_context)) {
3535
{
3636
PHP_V8_ENTER_STORED_ISOLATE(php_v8_context);
3737
PHP_V8_DECLARE_CONTEXT(php_v8_context);

Diff for: src/php_v8_function_template.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static void php_v8_function_template_free(zend_object *object) {
7979
* unmark it as weak and do all that cleanings in free handler. What about if object will be reused after being
8080
* unmarked as week? Note, that the only action on weak handler callback is Reset()ing persistent handler.
8181
*/
82-
if (zend_is_executing() && !CG(unclean_shutdown) && php_v8_function_template->persistent_data && !php_v8_function_template->persistent_data->empty()) {
82+
if (PHP_V8_IS_UP_AND_RUNNING() && php_v8_function_template->persistent_data && !php_v8_function_template->persistent_data->empty()) {
8383
php_v8_function_template_make_weak(php_v8_function_template);
8484
}
8585

@@ -89,7 +89,7 @@ static void php_v8_function_template_free(zend_object *object) {
8989
}
9090

9191
if (php_v8_function_template->persistent) {
92-
if (PHP_V8_ISOLATE_HAS_VALID_HANDLE(php_v8_function_template)) {
92+
if (PHP_V8_IS_UP_AND_RUNNING() && PHP_V8_ISOLATE_HAS_VALID_HANDLE(php_v8_function_template)) {
9393
php_v8_function_template->persistent->Reset();
9494
}
9595

Diff for: src/php_v8_object_template.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static HashTable * php_v8_object_template_gc(zval *object, zval **table, int *n)
7171
static void php_v8_object_template_free(zend_object *object) {
7272
php_v8_object_template_t *php_v8_object_template = php_v8_object_template_fetch_object(object);
7373

74-
if (zend_is_executing() && !CG(unclean_shutdown) && php_v8_object_template->persistent_data && !php_v8_object_template->persistent_data->empty()) {
74+
if (PHP_V8_IS_UP_AND_RUNNING() && php_v8_object_template->persistent_data && !php_v8_object_template->persistent_data->empty()) {
7575
php_v8_object_template_make_weak(php_v8_object_template);
7676
}
7777

@@ -81,7 +81,7 @@ static void php_v8_object_template_free(zend_object *object) {
8181
php_v8_object_template->persistent_data = NULL;
8282
}
8383

84-
if (php_v8_object_template->persistent) {
84+
if (PHP_V8_IS_UP_AND_RUNNING() && php_v8_object_template->persistent) {
8585
if (PHP_V8_ISOLATE_HAS_VALID_HANDLE(php_v8_object_template)) {
8686
php_v8_object_template->persistent->Reset();
8787
}

Diff for: src/php_v8_script.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static void php_v8_script_free(zend_object *object)
4949
php_v8_script_t *php_v8_script = php_v8_script_fetch_object(object);
5050

5151
if (php_v8_script->persistent) {
52-
if (PHP_V8_ISOLATE_HAS_VALID_HANDLE(php_v8_script)) {
52+
if (PHP_V8_IS_UP_AND_RUNNING() && PHP_V8_ISOLATE_HAS_VALID_HANDLE(php_v8_script)) {
5353
php_v8_script->persistent->Reset();
5454
}
5555
delete php_v8_script->persistent;

Diff for: src/php_v8_unbound_script.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static void php_v8_unbound_script_free(zend_object *object)
5050
php_v8_unbound_script_t *php_v8_unbound_script = php_v8_unbound_script_fetch_object(object);
5151

5252
if (php_v8_unbound_script->persistent) {
53-
if (PHP_V8_ISOLATE_HAS_VALID_HANDLE(php_v8_unbound_script)) {
53+
if (PHP_V8_IS_UP_AND_RUNNING() && PHP_V8_ISOLATE_HAS_VALID_HANDLE(php_v8_unbound_script)) {
5454
php_v8_unbound_script->persistent->Reset();
5555
}
5656
delete php_v8_unbound_script->persistent;

Diff for: src/php_v8_value.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static void php_v8_value_free(zend_object *object) {
122122

123123

124124
// TODO: making weak makes sense for objects only
125-
if (zend_is_executing() && !CG(unclean_shutdown) && php_v8_value->persistent_data && !php_v8_value->persistent_data->empty()) {
125+
if (PHP_V8_IS_UP_AND_RUNNING() && php_v8_value->persistent_data && !php_v8_value->persistent_data->empty()) {
126126
php_v8_value_make_weak(php_v8_value); // TODO: refactor logic for make weak to include checking whether it can be weak -> maybe_make_weak
127127
}
128128

@@ -135,7 +135,7 @@ static void php_v8_value_free(zend_object *object) {
135135
}
136136

137137
if (php_v8_value->persistent) {
138-
if (PHP_V8_ISOLATE_HAS_VALID_HANDLE(php_v8_value)) {
138+
if (PHP_V8_IS_UP_AND_RUNNING() && PHP_V8_ISOLATE_HAS_VALID_HANDLE(php_v8_value)) {
139139
php_v8_value->persistent->Reset();
140140
}
141141

0 commit comments

Comments
 (0)