Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: fix memory leak, when module require error occurs #32837

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/internal/modules/cjs/loader.js
Expand Up @@ -928,6 +928,13 @@ Module._load = function(request, parent, isMain) {
delete Module._cache[filename];
if (parent !== undefined) {
delete relativeResolveCache[relResolveCacheIdentifier];
const children = parent && parent.children;
if (ArrayIsArray(children)) {
const index = children.indexOf(module);
if (index !== -1) {
children.splice(index, 1);
}
}
}
} else if (module.exports &&
ObjectGetPrototypeOf(module.exports) ===
Expand Down
3 changes: 0 additions & 3 deletions test/sequential/test-module-loading.js
Expand Up @@ -302,17 +302,14 @@ assert.throws(
}
},
'fixtures/path.js': {},
'fixtures/throws_error.js': {},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit test for module loading, verify module.children contains all the different modules that we've required, but should not contain modules that failed to load

'fixtures/registerExt.test': {},
'fixtures/registerExt.hello.world': {},
'fixtures/registerExt2.test': {},
'fixtures/module-load-order/file1': {},
'fixtures/module-load-order/file2.js': {},
'fixtures/module-load-order/file3.node': {},
'fixtures/module-load-order/file4.reg': {},
'fixtures/module-load-order/file5.reg2': {},
'fixtures/module-load-order/file6/index.js': {},
'fixtures/module-load-order/file7/index.node': {},
'fixtures/module-load-order/file8/index.reg': {},
'fixtures/module-load-order/file9/index.reg2': {},
'fixtures/module-require/parent/index.js': {
Expand Down