Skip to content

Commit

Permalink
Fix segfault when assigning 'null' value to the context.
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdwerve committed Feb 23, 2017
1 parent 3cbbf33 commit 120fd7d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
22 changes: 17 additions & 5 deletions platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,17 @@ Platform::Platform() :
*/
Platform::~Platform()
{
// we are no longer running
_running = false;
// we stop the platform first
stop();
}

/**
* Stop running the platform.
*/
void Platform::stop()
{
// we set it to false, but if the old value was not true then we leap out
if (!_running.exchange(false)) return;

// signal the thread in case it is waiting for input
_condition.notify_one();
Expand Down Expand Up @@ -159,8 +168,8 @@ void Platform::shutdown()
// still not set, we need to create it now
if (result != nullptr)
{
// create the platform
delete result;
// we need to stop the platform before disposing and shutting it down
result->stop();

// and shut down the engine (this also takes care of the ICU) and the platform
v8::V8::Dispose();
Expand All @@ -171,7 +180,10 @@ void Platform::shutdown()

// store the new platform
platform.store(nullptr, std::memory_order_relaxed);
}

// delete the platform
delete result;
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class Platform : public v8::Platform
* @var std::thread
*/
std::thread _worker;

/**
* (blocking) method to stop running a platform.
*/
void stop();

/**
* Execute some work, this is called
Expand Down
2 changes: 1 addition & 1 deletion value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ v8::Handle<v8::Value> value(const Php::Value &input)
// the value can be of many types
switch (input.type())
{
case Php::Type::Null: /* don't set anything, let it be empty */ break;
case Php::Type::Null: result = v8::Null(Isolate::get()); break;
case Php::Type::Numeric: result = v8::Integer::New(Isolate::get(), input); break;
case Php::Type::Float: result = v8::Number::New(Isolate::get(), input); break;
case Php::Type::Bool: result = v8::Boolean::New(Isolate::get(), input); break;
Expand Down

0 comments on commit 120fd7d

Please sign in to comment.