Skip to content

Commit

Permalink
otp_crypto: make sure ensure heap size includes binary header
Browse files Browse the repository at this point in the history
Use term_binary_heap_size for exact size calculation before ensuring
memory.

Signed-off-by: Davide Bettio <davide@uninstall.it>
  • Loading branch information
bettio committed Nov 18, 2023
1 parent 2eeb24f commit 55b262b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/libAtomVM/otp_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,8 @@ static term nif_crypto_crypto_one_time(Context *ctx, int argc, term argv[])
free(allocated_iv_data);
free(allocated_data_data);

if (UNLIKELY(memory_ensure_free(ctx, temp_buf_size) != MEMORY_GC_OK)) {
int ensure_size = term_binary_heap_size(temp_buf_size);
if (UNLIKELY(memory_ensure_free(ctx, ensure_size) != MEMORY_GC_OK)) {
free(temp_buf);
RAISE_ERROR(OUT_OF_MEMORY_ATOM);
}
Expand Down

0 comments on commit 55b262b

Please sign in to comment.