Skip to content

Commit 0050509

Browse files
committed
Fix logic of exit_reason memory handling.
This is temporary fix as opposed to what is implemented in feature/smp. `exit_reason` should be allocated in the target process. If it is allocated in the ctx process, it will be copied to the target process during its next garbage collection, however this will impact the used memory size, which is used to ensure a given number of free terms. If `MIN_FREE_SPACE_SIZE` is lower than the size of the exit reason, the GC will allocate less bytes than expected. Signed-off-by: Paul Guyot <[email protected]>
1 parent b147b31 commit 0050509

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/libAtomVM/context.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,13 @@ static void context_monitors_handle_terminate(Context *ctx)
187187

188188
mailbox_send(target, info_tuple);
189189
} else {
190-
target->exit_reason = memory_copy_term_tree(&ctx->heap_ptr, ctx->exit_reason, &ctx->mso_list);
190+
size_t estimated_mem_usage = memory_estimate_usage(ctx->exit_reason);
191+
if (UNLIKELY(memory_ensure_free(target, estimated_mem_usage) != MEMORY_GC_OK)) {
192+
//TODO: handle out of memory here
193+
fprintf(stderr, "Cannot handle out of memory.\n");
194+
AVM_ABORT();
195+
}
196+
target->exit_reason = memory_copy_term_tree(&target->heap_ptr, ctx->exit_reason, &target->mso_list);
191197

192198
// TODO: this cannot work on multicore systems
193199
// target context should be marked as killed and terminated during next scheduling

0 commit comments

Comments
 (0)