From d8ce6dd806ea12ebafa312f6bb7f762084efd37a Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 8 Jun 2016 05:51:39 -0700 Subject: Do not leave COBJ-ified mp_int uninitialized. Here we ensure that the digits pointer of an uninitialized mp_int is nulled out. The garbage collector could conceivably encounter such an object, in which case mp_clear will then try to free a garbage pointer. This could happen if an exception is thrown out of numeric code due to low memory, interrupting its execution, leaving behind an unfilled object produced by make_ubignum. * arith.c (make_ubignum): Perform minimal initialization of the mp_int using new function. * mpi/mpi.h (mp_init_minimal): New inline function. --- mpi/mpi.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'mpi') diff --git a/mpi/mpi.h b/mpi/mpi.h index cd7e823d..aac49019 100644 --- a/mpi/mpi.h +++ b/mpi/mpi.h @@ -85,6 +85,11 @@ void mp_set_prec(unsigned int prec); /* Memory management */ mp_err mp_init(mp_int *mp); +INLINE mp_err mp_init_minimal(mp_int *mp) +{ + DIGITS(mp) = 0; + return MP_OKAY; +} mp_err mp_init_array(mp_int mp[], int count); mp_err mp_init_size(mp_int *mp, mp_size prec); mp_err mp_init_copy(mp_int *mp, mp_int *from); -- cgit v1.2.3