GeezerVison is showing github.com — module: fix leak of vm.SyntheticModule · nodejs/node@4e578f8
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/module_wrap.cc +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -64,6 +64,7 @@ ModuleWrap::ModuleWrap(Environment* env, |
64 | 64 | if (!synthetic_evaluation_step->IsUndefined()) { |
65 | 65 | synthetic_ = true; |
66 | 66 | } |
| 67 | + MakeWeak(); |
67 | 68 | } |
68 | 69 |
|
69 | 70 | ModuleWrap::~ModuleWrap() { |
|
Collapse file
Copy file name to clipboard +23Lines changed: 23 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Flags: --experimental-vm-modules --max-old-space-size=16 |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +// This tests that vm.SyntheticModule does not leak. |
| 5 | +// See https://github.com/nodejs/node/issues/44211 |
| 6 | +require('../common'); |
| 7 | +const vm = require('vm'); |
| 8 | + |
| 9 | +let count = 0; |
| 10 | +async function createModule() { |
| 11 | + // Try to reach the maximum old space size. |
| 12 | + const m = new vm.SyntheticModule(['bar'], () => { |
| 13 | + m.setExport('bar', new Array(512).fill('----')); |
| 14 | + }); |
| 15 | + await m.link(() => {}); |
| 16 | + await m.evaluate(); |
| 17 | + if (count++ < 4 * 1024) { |
| 18 | + setTimeout(createModule, 1); |
| 19 | + } |
| 20 | + return m; |
| 21 | +} |
| 22 | + |
| 23 | +createModule(); |