src: use unique_ptr for CachedData in ContextifyScript::New

This closes a memory leak.

PR-URL: https://github.com/nodejs/node/pull/33113
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
This commit is contained in:
Anna Henningsen 2020-04-28 04:06:09 +02:00
parent 526ff86aa9
commit e0ba4b1592
No known key found for this signature in database
GPG Key ID: A94130F0BFC8EBE9

View File

@ -764,8 +764,8 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {
env->cached_data_rejected_string(),
Boolean::New(isolate, source.GetCachedData()->rejected)).Check();
} else if (produce_cached_data) {
const ScriptCompiler::CachedData* cached_data =
ScriptCompiler::CreateCodeCache(v8_script.ToLocalChecked());
std::unique_ptr<ScriptCompiler::CachedData> cached_data {
ScriptCompiler::CreateCodeCache(v8_script.ToLocalChecked()) };
bool cached_data_produced = cached_data != nullptr;
if (cached_data_produced) {
MaybeLocal<Object> buf = Buffer::Copy(