diff --git a/src/node_snapshotable.cc b/src/node_snapshotable.cc index 55a65deeea6e74..32371a69588ce7 100644 --- a/src/node_snapshotable.cc +++ b/src/node_snapshotable.cc @@ -1357,9 +1357,11 @@ StartupData SerializeNodeContextInternalFields(Local holder, // To serialize the type field, save data in a EmbedderTypeInfo. if (index == BaseObject::kEmbedderType) { int size = sizeof(EmbedderTypeInfo); - char* data = new char[size]; // We need to use placement new because V8 calls delete[] on the returned // data. + // The () syntax at the end would zero-initialize the block and make + // the padding reproducible. + char* data = new char[size](); // TODO(joyeecheung): support cppgc objects. new (data) EmbedderTypeInfo(obj->type(), EmbedderTypeInfo::MemoryMode::kBaseObject); diff --git a/src/node_snapshotable.h b/src/node_snapshotable.h index 5e281b8155c810..4ae52d8f3ae747 100644 --- a/src/node_snapshotable.h +++ b/src/node_snapshotable.h @@ -47,6 +47,7 @@ struct InternalFieldInfoBase { std::is_same_v, "Can only accept InternalFieldInfoBase subclasses"); void* buf = ::operator new[](sizeof(T)); + memset(buf, 0, sizeof(T)); // Make the padding reproducible. T* result = new (buf) T; result->type = type; result->length = sizeof(T);