Skip to content

Handle memory exceptions errors in MEMFS #17232

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/library_memfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ mergeInto(LibraryManager.library, {
newCapacity = Math.max(newCapacity, (prevCapacity * (prevCapacity < CAPACITY_DOUBLING_MAX ? 2.0 : 1.125)) >>> 0);
if (prevCapacity != 0) newCapacity = Math.max(newCapacity, 256); // At minimum allocate 256b for each file when expanding.
var oldContents = node.contents;
node.contents = new Uint8Array(newCapacity); // Allocate new storage.
try {
node.contents = new Uint8Array(newCapacity); // Allocate new storage.
}
catch(e) {
Comment on lines +122 to +123
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
catch(e) {
} catch(e) {

throw new FS.ErrnoError({{{ cDefine('ENOMEM') }}});
}
if (node.usedBytes > 0) node.contents.set(oldContents.subarray(0, node.usedBytes), 0); // Copy old data over to the new storage.
},

Expand All @@ -132,7 +137,12 @@ mergeInto(LibraryManager.library, {
node.usedBytes = 0;
} else {
var oldContents = node.contents;
node.contents = new Uint8Array(newSize); // Allocate new storage.
try {
node.contents = new Uint8Array(newSize); // Allocate new storage.
}
catch(e) {
throw new FS.ErrnoError({{{ cDefine('ENOMEM') }}});
}
if (oldContents) {
node.contents.set(oldContents.subarray(0, Math.min(newSize, node.usedBytes))); // Copy old data over to the new storage.
}
Expand Down