From 354df9e8a179778d709a91e023a8f790c05aa0c5 Mon Sep 17 00:00:00 2001 From: Yash Ladha Date: Sat, 30 Jan 2021 13:50:21 +0530 Subject: [PATCH] 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 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Rich Trott --- src/env.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/env.cc b/src/env.cc index 16c6fcc3db4749..91789c3476f307 100644 --- a/src/env.cc +++ b/src/env.cc @@ -379,9 +379,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(options_->debug_options().host_port)); + options_ = std::make_shared( + *isolate_data->options()->per_env); + inspector_host_port_ = std::make_shared>( + options_->debug_options().host_port); if (!(flags_ & EnvironmentFlags::kOwnsProcessState)) { set_abort_on_uncaught_exception(false);