diff options
author | Daniel Bevenius <daniel.bevenius@gmail.com> | 2018-02-05 11:20:07 +0100 |
---|---|---|
committer | Daniel Bevenius <daniel.bevenius@gmail.com> | 2018-02-16 07:27:08 +0100 |
commit | 42c14c5c17c427aa82722fff41f3e723354239b9 (patch) | |
tree | c5430c97db3eb9ad1f081d0f5ee2182007272aef /test/cctest | |
parent | efb32592e1b78ec2559e1a409faa049e756a9501 (diff) | |
download | node-new-42c14c5c17c427aa82722fff41f3e723354239b9.tar.gz |
src: set thread local env in CreateEnvironment
This commit set the Environment as a thread local when CreateEnvironment
is called which is currently not being done. This would lead to a
segment fault if later node::AtExit is called without specifying the
environment parameter. This specific issue was reported by Electron.
If I recall correctly, back when this was implemented the motivation was
that if embedders have multiple environments per isolate they should be
using the AtExit functions that take an environment. This is not the
case with Electron which only create a single environment (as far as I
know), and if a native module calls AtExit this would lead to the
segment fault.
I was able to reproduce Electron issue and the provided test simulates
it. I was also able to use this patch and verify that it works for the
Electron issue as well.
PR-URL: https://github.com/nodejs/node/pull/18573
Refs: https://github.com/nodejs/node/pull/9163
Refs: https://github.com/electron/electron/issues/11299
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Matheus Marchini <matheus@sthima.com>
Diffstat (limited to 'test/cctest')
-rw-r--r-- | test/cctest/test_environment.cc | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/test/cctest/test_environment.cc b/test/cctest/test_environment.cc index c559a21fda..07170ac267 100644 --- a/test/cctest/test_environment.cc +++ b/test/cctest/test_environment.cc @@ -33,6 +33,16 @@ TEST_F(EnvironmentTest, AtExitWithEnvironment) { EXPECT_TRUE(called_cb_1); } +TEST_F(EnvironmentTest, AtExitWithoutEnvironment) { + const v8::HandleScope handle_scope(isolate_); + const Argv argv; + Env env {handle_scope, argv}; + + AtExit(at_exit_callback1); // No Environment is passed to AtExit. + RunAtExit(*env); + EXPECT_TRUE(called_cb_1); +} + TEST_F(EnvironmentTest, AtExitWithArgument) { const v8::HandleScope handle_scope(isolate_); const Argv argv; |