GeezerVison is showing github.com — src: zero-initialize data that are copied into the snapshot · nodejs/node@584beaa
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/node_snapshotable.cc +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1357,9 +1357,11 @@ StartupData SerializeNodeContextInternalFields(Local<Object> holder, |
1357 | 1357 | // To serialize the type field, save data in a EmbedderTypeInfo. |
1358 | 1358 | if (index == BaseObject::kEmbedderType) { |
1359 | 1359 | int size = sizeof(EmbedderTypeInfo); |
1360 | | - char* data = new char[size]; |
1361 | 1360 | // We need to use placement new because V8 calls delete[] on the returned |
1362 | 1361 | // data. |
| 1362 | + // The () syntax at the end would zero-initialize the block and make |
| 1363 | + // the padding reproducible. |
| 1364 | + char* data = new char[size](); |
1363 | 1365 | // TODO(joyeecheung): support cppgc objects. |
1364 | 1366 | new (data) EmbedderTypeInfo(obj->type(), |
1365 | 1367 | EmbedderTypeInfo::MemoryMode::kBaseObject); |
|
Collapse file
Copy file name to clipboardExpand all lines: src/node_snapshotable.h +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -47,6 +47,7 @@ struct InternalFieldInfoBase { |
47 | 47 | std::is_same_v<InternalFieldInfoBase, T>, |
48 | 48 | "Can only accept InternalFieldInfoBase subclasses"); |
49 | 49 | void* buf = ::operator new[](sizeof(T)); |
| 50 | + memset(buf, 0, sizeof(T)); // Make the padding reproducible. |
50 | 51 | T* result = new (buf) T; |
51 | 52 | result->type = type; |
52 | 53 | result->length = sizeof(T); |
|