Skip to content

Commit 7b5b409

Browse files
committed
Merge pull request atomvm#512 from pguyot/w16/add-missing-memory_ensure_free-in-nif_openssl_random
Add missing memory_ensure_free in `nif_openssl_random` 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
2 parents b147b31 + ebef40d commit 7b5b409

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/platforms/generic_unix/lib/platform_nifs.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ static term nif_openssl_random(Context *ctx, int argc, term argv[])
100100
return t;
101101
}
102102
uint32_t *r = (uint32_t *) term_binary_data(t);
103-
return term_make_boxed_int(*r, ctx);
103+
avm_int_t value = *r;
104+
if (UNLIKELY(memory_ensure_free(ctx, BOXED_INT_SIZE) != MEMORY_GC_OK)) {
105+
RAISE_ERROR(OUT_OF_MEMORY_ATOM);
106+
}
107+
return term_make_boxed_int(value, ctx);
104108
}
105109

106110
static const struct Nif openssl_md5_nif =

0 commit comments

Comments
 (0)