-
Notifications
You must be signed in to change notification settings - Fork 3.4k
abort() on malloc() failure in new with exceptions disabled #11079
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
Changes from 3 commits
95c174e
d93658c
45403cc
3e3b7b5
9484ba9
27b2ef1
d3342ef
0948f76
02ac456
2ca0dde
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <emscripten.h> | ||
#include <stdio.h> | ||
#include <vector> | ||
|
||
EMSCRIPTEN_KEEPALIVE extern "C" void allocate_too_much() { | ||
std::vector<int> x; | ||
puts("allocating more than TOTAL_MEMORY; this will fail."); | ||
x.resize(20 * 1024 * 1024); | ||
puts("oh no, it didn't fail!"); | ||
} | ||
|
||
int main() { | ||
EM_ASM({ | ||
// Catch the failure here so we can report it. | ||
try { | ||
_allocate_too_much(); | ||
out("no error happened"); | ||
} catch (e) { | ||
assert(("" + e).indexOf("abort") >= 0, "expect an abort"); | ||
out("an expected error occurred"); | ||
kripken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
an expected error occurred |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2169,6 +2169,11 @@ def test_memorygrowth_3_force_fail_reallocBuffer(self): | |
self.emcc_args += ['-Wno-almost-asm', '-s', 'ALLOW_MEMORY_GROWTH=1', '-s', 'TEST_MEMORY_GROWTH_FAILS=1'] | ||
self.do_run_in_out_file_test('tests', 'core', 'test_memorygrowth_3') | ||
|
||
def test_memorygrowth_new_error(self): | ||
# test that C++ new properly errors if we fail to malloc | ||
self.emcc_args += ['-Wno-almost-asm', '-s', 'ALLOW_MEMORY_GROWTH=1', '-s', 'MAXIMUM_MEMORY=18MB'] | ||
self.do_run_in_out_file_test('tests', 'core', 'test_memorygrowth_new_error') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does doesn't seem related to memory growth. Why not just not set any settings and leave the default 16Mb memory. The result should be the same. Then we can just call this test something like: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add a comment - this is actually related to memory growth. When growth is disabled, we abort() in another code path (the code to grow memory looks very different in the two cases). |
||
|
||
@no_asmjs() | ||
@no_wasm2js('no WebAssembly.Memory()') | ||
@no_asan('ASan alters the memory size') | ||
|
Uh oh!
There was an error while loading. Please reload this page.