Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Unified Diff: src/api.cc

Issue 2402633002: [wasm] Fix memory bug (Closed)
Patch Set: Add TODO Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 6bb15d2e268a01eefff367e45a2eee5cdb823f6a..3a72b360fb7fefcb17f218b2e8ca16ae14369d13 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -7246,10 +7246,15 @@ MaybeLocal<WasmCompiledModule> WasmCompiledModule::Compile(
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
i::wasm::ErrorThrower thrower(i_isolate, "WasmCompiledModule::Deserialize()");
i::SeqOneByteString* data = i::SeqOneByteString::cast(*module_bytes);
+ // Copy bytes such that GC can not move it during construction of the module.
+ // TODO(wasm): Avoid this additional copy.
+ i::ScopedVector<unsigned char> bytes_copy(data->length());
+ memcpy(bytes_copy.start(), data->GetChars(), data->length());
i::MaybeHandle<i::JSObject> maybe_compiled =
i::wasm::CreateModuleObjectFromBytes(
- i_isolate, data->GetChars(), data->GetChars() + data->length(),
- &thrower, i::wasm::ModuleOrigin::kWasmOrigin);
+ i_isolate, bytes_copy.start(),
+ bytes_copy.start() + bytes_copy.length(), &thrower,
+ i::wasm::ModuleOrigin::kWasmOrigin);
if (maybe_compiled.is_null()) return MaybeLocal<WasmCompiledModule>();
return Local<WasmCompiledModule>::Cast(
Utils::ToLocal(maybe_compiled.ToHandleChecked()));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698