Skip to content

Commit

Permalink
Merge pull request #952 from bettio/crypto_one_time-fix-ensure-size
Browse files Browse the repository at this point in the history
otp_crypto: make sure ensure heap size includes binary header

Use term_binary_heap_size for exact size calculation before ensuring memory.

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
  • Loading branch information
bettio committed Nov 19, 2023
2 parents 2eeb24f + 55b262b commit 3af5f64
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 3af5f64

Please sign in to comment.