Skip to content

Commit 11f7392

Browse files
committed
Don't destroy v8::Platform global instance on exit (rubyjs#323)
This is not a bug fix per se but it does mitigate a number of crashes at program exit. It's not safe to tear down the Platform instance if the program terminates abnormally.
1 parent 9aabb0e commit 11f7392

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

ext/mini_racer_extension/mini_racer_extension.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,10 @@ static VALUE rb_mJSON;
301301
static VALUE rb_cFailedV8Conversion;
302302
static VALUE rb_cDateTime = Qnil;
303303

304-
static std::unique_ptr<Platform> current_platform = NULL;
304+
// note: |current_platform| is deliberately leaked on program exit
305+
// because it's not safe to destroy it after main() has exited;
306+
// abnormal termination may have left V8 in an undefined state
307+
static Platform *current_platform;
305308
static std::mutex platform_lock;
306309

307310
static pthread_attr_t *thread_attr_p;
@@ -366,11 +369,11 @@ static void init_v8() {
366369
if (current_platform == NULL) {
367370
V8::InitializeICU();
368371
if (single_threaded) {
369-
current_platform = platform::NewSingleThreadedDefaultPlatform();
372+
current_platform = platform::NewSingleThreadedDefaultPlatform().release();
370373
} else {
371-
current_platform = platform::NewDefaultPlatform();
374+
current_platform = platform::NewDefaultPlatform().release();
372375
}
373-
V8::InitializePlatform(current_platform.get());
376+
V8::InitializePlatform(current_platform);
374377
V8::Initialize();
375378
}
376379

@@ -1006,7 +1009,7 @@ static VALUE rb_isolate_pump_message_loop(VALUE self) {
10061009

10071010
Locker guard { isolate_info->isolate };
10081011

1009-
if (platform::PumpMessageLoop(current_platform.get(), isolate_info->isolate)){
1012+
if (platform::PumpMessageLoop(current_platform, isolate_info->isolate)){
10101013
return Qtrue;
10111014
} else {
10121015
return Qfalse;

0 commit comments

Comments
 (0)