Skip to content

Commit 641d57f

Browse files
committed
src: manage MakeContext() pointer with unique_ptr
PR-URL: #28616 Refs: #28452 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent fe1b96d commit 641d57f

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/node_contextify.cc

+3-6
Original file line numberDiff line numberDiff line change
@@ -255,24 +255,21 @@ void ContextifyContext::MakeContext(const FunctionCallbackInfo<Value>& args) {
255255
options.allow_code_gen_wasm = args[4].As<Boolean>();
256256

257257
TryCatchScope try_catch(env);
258-
ContextifyContext* context = new ContextifyContext(env, sandbox, options);
258+
auto context_ptr = std::make_unique<ContextifyContext>(env, sandbox, options);
259259

260260
if (try_catch.HasCaught()) {
261261
if (!try_catch.HasTerminated())
262262
try_catch.ReThrow();
263-
delete context;
264263
return;
265264
}
266265

267-
if (context->context().IsEmpty()) {
268-
delete context;
266+
if (context_ptr->context().IsEmpty())
269267
return;
270-
}
271268

272269
sandbox->SetPrivate(
273270
env->context(),
274271
env->contextify_context_private_symbol(),
275-
External::New(env->isolate(), context));
272+
External::New(env->isolate(), context_ptr.release()));
276273
}
277274

278275

0 commit comments

Comments
 (0)