diff options
author | Yash Ladha <yashladhapankajladha123@gmail.com> | 2021-01-30 11:20:21 +0300 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2021-02-06 20:03:15 +0300 |
commit | 36cc0ee993a07174f47ea598b6c2c75a66cb052c (patch) | |
tree | 593dfa4fbc0cb2d46f41f68953dcc3ba2575c200 /src/env.cc | |
parent | 5ef4c64e5b912aa2f90d73ea08753362ec396c36 (diff) |
src: use make_shared for safe allocation
Using the reset does a double allocation and is error prone if some
exception occured which is very unlikely but can happen. make_shared_ptr
gives hedge over this and handle the failure in allocation.
PR-URL: https://github.com/nodejs/node/pull/37139
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src/env.cc')
-rw-r--r-- | src/env.cc | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/env.cc b/src/env.cc index fe774b4bf31..ea93574a388 100644 --- a/src/env.cc +++ b/src/env.cc @@ -375,9 +375,10 @@ Environment::Environment(IsolateData* isolate_data, // easier to modify them after Environment creation. The defaults are // part of the per-Isolate option set, for which in turn the defaults are // part of the per-process option set. - options_.reset(new EnvironmentOptions(*isolate_data->options()->per_env)); - inspector_host_port_.reset( - new ExclusiveAccess<HostPort>(options_->debug_options().host_port)); + options_ = std::make_shared<EnvironmentOptions>( + *isolate_data->options()->per_env); + inspector_host_port_ = std::make_shared<ExclusiveAccess<HostPort>>( + options_->debug_options().host_port); if (!(flags_ & EnvironmentFlags::kOwnsProcessState)) { set_abort_on_uncaught_exception(false); |