From 88d9676e74d928653f9b02a3fc9fbc7373055b1f 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 ed71905ff3072b..eed282a3e5db20 100644 --- a/src/env.cc +++ b/src/env.cc @@ -343,9 +343,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);