Skip to content

Commit 4f368c1

Browse files
committed
module: do not abort when OOM while loading literal
Literals are encoded as external terms, so they might make use of heap fragments and their memory allocation might fail. Existing code already deal with this, so we can just raise instead of abort(). There is still a very very low change we found a corrupt external term, but we are not able to distinguish the situations, so we also print a warning. Signed-off-by: Davide Bettio <davide@uninstall.it>
1 parent 78f8c13 commit 4f368c1

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ memory error
6767
- Fixed nif_atomvm_posix_read GC bug
6868
- Fixed `erlang:is_number/1` function, now returns true also for floats
6969
- Fixed unlink protocol and add support for `link/1` on ports
70+
- Do not abort when an out of memory happens while loading a literal value
7071

7172
### Changed
7273

src/libAtomVM/module.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,8 @@ term module_load_literal(Module *mod, int index, Context *ctx)
426426
{
427427
term t = externalterm_to_term(mod->literals_table[index].data, mod->literals_table[index].size,
428428
ctx, ExternalTermToHeapFragment);
429-
if (term_is_invalid_term(t)) {
430-
fprintf(stderr, "Invalid term reading literals_table[%i] from module\n", index);
431-
AVM_ABORT();
429+
if (UNLIKELY(term_is_invalid_term(t))) {
430+
fprintf(stderr, "Either OOM or invalid term while reading literals_table[%i] from module\n", index);
432431
}
433432
return t;
434433
}

0 commit comments

Comments
 (0)