From a52a08b078a11a11cde83b6191b812e2e171e781 Mon Sep 17 00:00:00 2001 From: Sander in 't Veld Date: Thu, 13 Apr 2017 14:13:15 +0200 Subject: [PATCH] Fixed segfault that occurred only when a timeout was set. --- context.cpp | 8 +++----- context.h | 1 + stack.h | 2 +- tests/test4.php | 6 +++++- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/context.cpp b/context.cpp index f51263f..63140c2 100644 --- a/context.cpp +++ b/context.cpp @@ -141,6 +141,7 @@ void Context::assign(Php::Parameters ¶ms) * * @param params array with one parameter: the code to execute * @return Php::Value + * @throws Php::Exception */ Php::Value Context::evaluate(Php::Parameters ¶ms) { @@ -196,14 +197,11 @@ Php::Value Context::evaluate(Php::Parameters ¶ms) // in case we timeout we must terminate execution if (status != std::cv_status::timeout) return; - // create a handle, so the local variable created below falls out of scope + // create a handle for the local variable that is created by dereferencing _context v8::HandleScope scope(Isolate::get()); - // access the main threads context - v8::Local context(_context); - // terminate execution - context->GetIsolate()->TerminateExecution(); + _context->GetIsolate()->TerminateExecution(); })); // execute the script diff --git a/context.h b/context.h index f1d22ff..5e09e3a 100644 --- a/context.h +++ b/context.h @@ -116,6 +116,7 @@ class Context : public Php::Base * * @param params array with one parameter: the code to execute * @return Php::Value + * @throws Php::Exception */ Php::Value evaluate(Php::Parameters ¶ms); }; diff --git a/stack.h b/stack.h index 90e43fe..d3608bb 100644 --- a/stack.h +++ b/stack.h @@ -91,7 +91,7 @@ class Stack * * @return v8::Local */ - operator v8::Local () const + operator const v8::Local () const { // create the value return v8::Local::New(Isolate::get(), _handle); diff --git a/tests/test4.php b/tests/test4.php index c8497e1..a9b7d71 100644 --- a/tests/test4.php +++ b/tests/test4.php @@ -2,4 +2,8 @@ $context = new JS\Context(); -$context->evaluate("3;", 5); +for ($i = 1; $i <= 1000000; $i++) +{ + if ($i % 1000 == 0) echo($i . PHP_EOL); + $context->evaluate("$i;", 1); +}