diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-06-08 05:51:39 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-06-08 05:51:39 -0700 |
commit | d8ce6dd806ea12ebafa312f6bb7f762084efd37a (patch) | |
tree | 5f4b4bf2df7aec19cda3ae42fc90e8c5e1ee4422 /mpi | |
parent | ede703bad4192140ac637a2bff3603e5a5567510 (diff) | |
download | txr-d8ce6dd806ea12ebafa312f6bb7f762084efd37a.tar.gz txr-d8ce6dd806ea12ebafa312f6bb7f762084efd37a.tar.bz2 txr-d8ce6dd806ea12ebafa312f6bb7f762084efd37a.zip |
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.
Diffstat (limited to 'mpi')
-rw-r--r-- | mpi/mpi.h | 5 |
1 files changed, 5 insertions, 0 deletions
@@ -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); |