Skip to content

Instantly share code, notes, and snippets.

@haxiomic
Created February 1, 2016 21:12
Show Gist options
  • Save haxiomic/502227a9f0c606cd6117 to your computer and use it in GitHub Desktop.
Save haxiomic/502227a9f0c606cd6117 to your computer and use it in GitHub Desktop.
isolate->Dispose() Crash
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "include/libplatform/libplatform.h"
#include "include/v8.h"
using namespace v8;
class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
public:
virtual void* Allocate(size_t length) {
void* data = AllocateUninitialized(length);
return data == NULL ? data : memset(data, 0, length);
}
virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
virtual void Free(void* data, size_t) { free(data); }
};
Isolate* isolate;
Platform* plat;
void Initialize(const char* startupDataDir){
// Initialize V8.
V8::InitializeICU();
V8::InitializeExternalStartupData(startupDataDir);
plat = platform::CreateDefaultPlatform();
V8::InitializePlatform(plat);
V8::Initialize();
// Create a new Isolate and make it the current one.
ArrayBufferAllocator allocator;
Isolate::CreateParams create_params;
create_params.array_buffer_allocator = &allocator;
isolate = Isolate::New(create_params);
{
Isolate::Scope isolate_scope(isolate);
// Create a stack-allocated handle scope.
HandleScope handle_scope(isolate);
// Create a new context.
Local<Context> context = Context::New(isolate);
// Enter the context for compiling and running the hello world script.
Context::Scope context_scope(context);
// Create a string containing the JavaScript source code.
Local<String> source =
String::NewFromUtf8(isolate, " Math.random(); ",
NewStringType::kNormal).ToLocalChecked();
// Compile the source code.
Local<Script> script = Script::Compile(context, source).ToLocalChecked();
// Run the script to get the result.
Local<Value> result = script->Run(context).ToLocalChecked();
// Convert the result to an UTF8 string and print it.
String::Utf8Value utf8(result);
printf("%s\n", *utf8);
}
}
void Dispose(){
// Dispose the isolate and tear down V8.
isolate->Dispose();
V8::Dispose();
V8::ShutdownPlatform();
delete plat;
}
int main(int argc, char* argv[]) {
Initialize(argv[0]);
Dispose();
return 0;
}
@haxiomic
Copy link
Author

haxiomic commented Feb 1, 2016

Process: test-crash [70651]
Path: /Users/USER/Desktop/*/test-crash
Identifier: test-crash
Version: 0
Code Type: X86-64 (Native)
Parent Process: bash [1458]
Responsible: Terminal [1456]
User ID: 501

Date/Time: 2016-02-01 21:09:03.714 +0000
OS Version: Mac OS X 10.11.3 (15D21)
Report Version: 11
Anonymous UUID: D9BB94FA-05CF-AA50-8944-23C3AD6A915E

Sleep/Wake UUID: BA350547-450C-42A9-ADFB-7921EB449C1E

Time Awake Since Boot: 25000 seconds
Time Since Wake: 2300 seconds

System Integrity Protection: disabled

Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00007fae00080024

VM Regions Near 0x7fae00080024:
Stack 000070000018a000-000070000020c000 [ 520K] rw-/rwx SM=COW thread 4
-->
MALLOC_TINY 00007faebac00000-00007faebae00000 [ 2048K] rw-/rwx SM=PRV

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 test-crash 0x00000001033ebb63 v8::internal::ArrayBufferTracker::~ArrayBufferTracker() + 67 (array-buffer-tracker.cc:19)
1 test-crash 0x0000000103407147 v8::internal::Heap::TearDown() + 903 (heap.cc:5305)
2 test-crash 0x000000010348ef9f v8::internal::Isolate::Deinit() + 479 (isolate.cc:1943)
3 test-crash 0x000000010348ecb0 v8::internal::Isolate::TearDown() + 80 (atomicops_internals_mac.h:200)
4 test-crash 0x0000000103899e54 Dispose() + 20
5 test-crash 0x0000000103899eb7 main + 39
6 libdyld.dylib 0x00007fff9a64a5ad start + 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment