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

Fix SIGSEGV cause by WeakMap mem leak #350

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kasonyang
Copy link

Values in WeakMap may leaks and causes SIGSEGV error.

Reproduction example:

import * as std from 'std';
const weak1 = new WeakMap();
const weak2 = new WeakMap();
function createCyclicKey() {
    const parent = {};
    const child = {parent};
    parent.child = child;
    return child;
}
function testWeakMap() {
    const cyclicKey = createCyclicKey();
    const valueOfCyclicKey = {};
    weak1.set(cyclicKey, valueOfCyclicKey);
    weak2.set(valueOfCyclicKey, 1);
}
testWeakMap();
// Force to free cyclicKey.
std.gc();
// Here will cause sigsegv because [cyclicKey] and [valueOfCyclicKey] in [weak1] was free,
// but weak2's map record was not removed, and it's key refers [valueOfCyclicKey] which is free.
weak2.get({});
console.log("end");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant